From e294463b8aeed7f9c120ec2a7c4ee3b188cad13c Mon Sep 17 00:00:00 2001 From: r-gochain <40002763+r-gochain@users.noreply.github.com> Date: Mon, 18 Aug 2025 22:31:47 -0400 Subject: [PATCH] Update stringy.js to correctly handle ' and " --- src/stringy.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/stringy.js b/src/stringy.js index 18fb2d1..78f781b 100644 --- a/src/stringy.js +++ b/src/stringy.js @@ -1,16 +1,22 @@ // stringify is for passing objects as html atttributes. // JSON.stringify doesn't work if your object has double and single quotes as it will end the string early. export function stringifyAttribute(ob) { - if(!ob) return '' - let s = '' + if (!ob) { + return '' + } + + let s if (typeof ob === 'string') { s = ob } else { s = JSON.stringify(ob) } - s = s.replaceAll( - '"', - '"' - ) + + // Escape double quotes for HTML attributes + s = s.replaceAll('"', '"') + + // Escape single quotes for HTML attributes + s = s.replaceAll("'", ''') + return s }