Skip to content

Commit

Permalink
Merge pull request #38 from lightning-js/fix/single-quote-escape
Browse files Browse the repository at this point in the history
fixed single quote escaping for all browsers
  • Loading branch information
michielvandergeest authored Jan 30, 2024
2 parents 390f263 + 114fcea commit 27ba505
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/codegenerator/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,12 @@ const cast = (val = '', key = false, component = 'component.') => {
if (val.startsWith('$')) {
castedValue = `${component}${val.replace('$', '')}`
} else {
// unescaped single quotes must be escaped
castedValue = `'${parseInlineContent(val.replace(/(?<!\\)'/g, "\\'"), component)}'`
// unescaped single quotes must be escaped while preserving escaped backslashes
const escapedVal = val
.replace(/\\\\/g, '__DOUBLE_BACKSLASH__')
.replace(/(^|[^\\])'/g, "$1\\'")
.replace(/__DOUBLE_BACKSLASH__/g, '\\\\')
castedValue = `'${parseInlineContent(escapedVal, component)}'`
}
}
// numeric
Expand Down

0 comments on commit 27ba505

Please sign in to comment.