Skip to content

Encoding errors #1

@keithbrink

Description

@keithbrink

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions