kvnang / workers-og

An `og:image` (social card) generator that is fast, browser-less (no Puppeteer), and capable of running on the edge. This package is designed to be used with Cloudflare Workers (but may be used elsewhere), with the simple API inspired by `@vercel/og`.
MIT License
194 stars 18 forks source link

Unnecessary Escaping of '&' Character in sanitizeJSON Function #6

Closed kiyopikko closed 8 months ago

kiyopikko commented 9 months ago

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 πŸ™‡

kvnang commented 8 months ago

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: https://github.com/kvnang/workers-og/commit/9866f9b2c1722252757cb464fa8f133c419b3a56