This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: replace escapeJSONforHTML(JSON.stringify()) by a single ser…
…ialize() method Ref #397
- Loading branch information
Showing
6 changed files
with
57 additions
and
27 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import test from "ava" | ||
|
||
import serializer from ".." | ||
|
||
test("serialize JS for HTML", (t) => { | ||
const escaped = serializer("<script></script><script></script>") | ||
t.is( | ||
escaped, | ||
"\"<script><\\/script><script><\\/script>\"", | ||
"function should escape all end of script tag" | ||
) | ||
t.falsy( | ||
escaped.includes("</script>"), | ||
"result should not contain unescaped end of script tag" | ||
) | ||
}) | ||
|
||
/* serialize-javascript version | ||
test("serialize JS object", (t) => { | ||
const serialized = serializer("<script></script><script></script>") | ||
t.is( | ||
serialized, | ||
"\"\\u003Cscript\\u003E\\u003C\\u002Fscript\\u003E" + | ||
"\\u003Cscript\\u003E\\u003C\\u002Fscript\\u003E\"", | ||
"function should escape all end of script tag" | ||
) | ||
t.falsy( | ||
serialized.includes("</script>"), | ||
"result should not contain unescaped end of script tag" | ||
) | ||
}) | ||
*/ | ||
|
||
// https://github.com/MoOx/phenomic/issues/397 | ||
// blocked by | ||
// https://github.com/MoOx/phenomic/issues/434 | ||
// and also | ||
// https://github.com/yahoo/serialize-javascript/pull/16 | ||
/* | ||
test("keep date", (t) => { | ||
const ISODate = "2016-04-28T22:02:17.156Z" | ||
t.is( | ||
serializer({ d: new Date(ISODate) }), | ||
`{"d":new Date("${ ISODate }")}`, | ||
) | ||
}) | ||
*/ |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// @flow | ||
|
||
export default (value: any): string => { | ||
return JSON.stringify(value).replace(/\<\/script>/g, "<\\/script>") | ||
} |
This file contains 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 characters
This file contains 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 characters