Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding errors #1

Open
keithbrink opened this issue Oct 12, 2018 · 1 comment
Open

Encoding errors #1

keithbrink opened this issue Oct 12, 2018 · 1 comment

Comments

@keithbrink
Copy link

Hey there, I am getting a few errors when encoding a Javascript object:

  1. In an object that looks something like this:
...
"long_description":"The \"shufflebuilding\" game Smash Up starts with a simple premise: Take the twenty-card decks of two factions, shuffle <br> them into a forty-card deck, then compete to smash more Bases than your opponents! Each faction brings a different <br> game mechanism into play - pirates move cards, zombies bring cards back from the discard pile, dinosaurs have huge<br> power, and every combination of factions brings a different play experience.<br>",
...

All of the spaces are stripped from the description, resulting in:

...
The\"shufflebuilding\"gameSmashUpstartswithasimplepremise:Takethetwenty-carddecksoftwofactions,shuffle<br>themintoaforty-carddeck
...

Then, anything that has a colon at the end of it has quotes added:

...
The\"shufflebuilding\""gameSmashUpstartswithasimplepremise":Takethetwenty-carddecksoftwofactions,shuffle<br>themintoaforty-carddeck
...

This creates an invalid JSON object.

  1. In an object that looks like this:
...
"thumbnails":{"small":"https:\/\/www.x.com\/images\/default\/products\/x.png","medium":"https:\/\/www.x.com\/images\/default\/products\/x.png","large":"https:\/\/www.x.com\/images\/default\/products\/x.png"},
...

The https protocol has quotes added around it, similar to the previous issue. I was able to resolve this issue by changing your regex to the following:

$str = preg_replace('/([a-zA-Z0-9\_]+):(?!\\\\)/', '"$1":', $str);

But it's an incomplete solution at best.

Thanks for putting this package together!

@Osushi
Copy link
Owner

Osushi commented Oct 12, 2018

Thanks for your reporting, I'm happy!
I consider to fix bugs. Please wait few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants