diff --git a/src/function.ts b/src/function.ts index 5319549..97a8929 100644 --- a/src/function.ts +++ b/src/function.ts @@ -4,7 +4,6 @@ import { quoteKey, isValidVariableName } from "./quote"; /** * Used in function stringification. */ -/* istanbul ignore next */ const METHOD_NAMES_ARE_QUOTED = { " "() { diff --git a/src/index.spec.ts b/src/index.spec.ts index e03d411..67fe28d 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -82,6 +82,8 @@ describe("javascript-stringify", () => { "should escape certain unicode sequences", test("\u0602", "'\\u0602'"), ); + + it("should escape < for safety", test("", "'\\u003c/script>'")); }); describe("numbers", () => { @@ -89,7 +91,7 @@ describe("javascript-stringify", () => { it("should stringify floats", test(10.5, "10.5")); - it('should stringify "NaN"', test(10.5, "10.5")); + it('should stringify "NaN"', test(NaN, "NaN")); it('should stringify "Infinity"', test(Infinity, "Infinity")); @@ -219,7 +221,20 @@ describe("javascript-stringify", () => { }); describe("RegExp", () => { - it("should stringify as shorthand", test(/[abc]/gi, "/[abc]/gi")); + it( + "should stringify as shorthand", + test(/[abc]/gi, "new RegExp('[abc]', 'gi')"), + ); + + it( + "should escape slashes", + test(new RegExp("a/b"), "new RegExp('a\\\\/b')"), + ); + + it( + "should escape html characters", + test(new RegExp("