kvnang/workers-og

Unnecessary Escaping of '&' Character in sanitizeJSON Function

Closed this issue · 1 comments

Thank you for great project!

I've encountered an issue with the sanitizeJSON function, where it unnecessarily escapes the & character. This behavior seems to be causing issues when parsing JSON strings.

export const sanitizeJSON = (unsanitized: string) => {
  return unsanitized
    .replace(/\\/g, "\\\\")
    .replace(/\n/g, "\\n")
    .replace(/\r/g, "\\r")
    .replace(/\t/g, "\\t")
    .replace(/\f/g, "\\f")
    .replace(/"/g, '\\"')
    .replace(/\&/g, "\\&"); // this line
};
スクリーンショット 2024-01-11 1 53 15

If I've misunderstood something, I apologize 🙇

Thanks! You're right, as per json.org the ampersand shouldn't be escaped. I've published the new version on NPM based on this commit here:
9866f9b