Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,9 @@ function useDoubleQuote(node, options) {
if (node.isDoubleQuote === options.singleQuote) {
// We have a double quote and the user passed singleQuote:true, or the other way around.
const rawValue = node.raw.slice(node.raw[0] === "b" ? 2 : 1, -1);
// In double quotes, PHP reads any `\u{` as a code point escape and rejects an invalid one.
const isComplex = rawValue.match(
/\\([$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u{([0-9a-fA-F]+)})|\r?\n|'|"|\$/
/\\([$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u{)|\r?\n|'|"|\$/
);
return node.isDoubleQuote ? isComplex : !isComplex;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/string-double-quote/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ singleQuote: false
'\\u{aa}';
'\\u{0000aa}';
'\\u{9999}';
'\\u{%04X}';
'\\u{';
'\\u{zz}';
'multi
line';
'\\\\';
Expand Down Expand Up @@ -73,6 +76,9 @@ b'binary string\\n';
'\\u{aa}';
'\\u{0000aa}';
'\\u{9999}';
'\\u{%04X}';
'\\u{';
'\\u{zz}';
'multi
line';
"\\\\";
Expand Down
3 changes: 3 additions & 0 deletions tests/string-double-quote/quoting.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
'\u{aa}';
'\u{0000aa}';
'\u{9999}';
'\u{%04X}';
'\u{';
'\u{zz}';
'multi
line';
'\\';
Expand Down