Last active
January 4, 2021 16:39
-
-
Save danschumann/ae0b5bdcf2e1cd1f4b61 to your computer and use it in GitHub Desktop.
Revisions
-
danschumann revised this gist
Aug 18, 2014 . 1 changed file with 0 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,3 @@ myObject = { ... } this.injectString = JSON.stringify( myObject ).replace(/\\/g, '\\\\').replace(/"/g, '\\\"') -
danschumann revised this gist
Aug 18, 2014 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,9 @@ myObject = { ... } // This should cover all the bases for what kinds of text the object has. // We replace \ with \\ and " with \" so that it can be 1 string when it is printed in html // We are replacing because it needs to be passed to frontend through JSON.parse("..."); // "{"mykey":"my\"val"}" -- pre-regex -- not parseable // "{\"mykey\":\"my\\\"val\"}" -- post-regex -- parseable // the first replace is for `my\"val`, since the second replace would cause that to break this.injectString = JSON.stringify( myObject ).replace(/\\/g, '\\\\').replace(/"/g, '\\\"') -
danschumann revised this gist
Aug 18, 2014 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
danschumann revised this gist
Aug 18, 2014 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
danschumann revised this gist
Aug 18, 2014 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ We only worry about parsing now, since everything should have been properly escaped <script> window.myObjectFrontend = JSON.parse("<%- @injectString %>"); </script> -
danschumann created this gist
Aug 18, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ We only worry about parsing now, since everything should have been properly escaped <script> window.groups = JSON.parse("<%- @injectString %>"); </script> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ myObject = { ... } // This should cover all the bases for what kinds of text the object has. this.injectString = JSON.stringify( myObject ).replace(/\\/g, '\\\\').replace(/"/g, '\\\"')