ember-fastboot / ember-fastboot/ember-cli-fastboot

ShoeBox: De-Serializing Throws if there is a \ in the content

Open
#355 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
850
Forks
161
Avg merge
17h 45m
Merged PRs (30d)
19

Description

This seems to be related to extracting the json out of the script tag using `.textContent()`. And... it results in a silent error.

Assuming this sort of a payload...
```
{"prop":"value with \ in it"}
```
Using the same process as Shoebox...
```
// get the text content of the element...
var tc = document.querySelector('#shoebox').textContent;
var data = JSON.parse(tc); // <-- THIS THROWS
```
Repro in jsbin: https://jsbin.com/yezehe/edit?html,js,output

For our team, we wanted to use Shoebox to start ensuring our client app *can* run in Fastboot - but for now we are still serving index.html using Rails. As for how/why we have this sort of thing in our payload, the app is completely configurable by customers - it's a minimalist version of Wix specific to our customers - and try as we might, they seem to find places where they can get `\`'s into the payload.

The app itself works just fine if we xhr the same payload - the issue only arises when the payload is inlined using this technique.

We are working around it for now by creating global scope objects and plucking the data from that into the ember app... ie...

```
window.__dataStore.someObj = {"prop":"value with \ in it"}
```
And since that does not rely on `.textContent()` of the script DOM node, everything is happy.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.