diff --git a/src/util.mjs b/src/util.mjs index 8a4aa944d..d97087240 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -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; } diff --git a/tests/string-double-quote/__snapshots__/jsfmt.spec.mjs.snap b/tests/string-double-quote/__snapshots__/jsfmt.spec.mjs.snap index 451d79ebd..848bcfbfa 100644 --- a/tests/string-double-quote/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/string-double-quote/__snapshots__/jsfmt.spec.mjs.snap @@ -34,6 +34,9 @@ singleQuote: false '\\u{aa}'; '\\u{0000aa}'; '\\u{9999}'; +'\\u{%04X}'; +'\\u{'; +'\\u{zz}'; 'multi line'; '\\\\'; @@ -73,6 +76,9 @@ b'binary string\\n'; '\\u{aa}'; '\\u{0000aa}'; '\\u{9999}'; +'\\u{%04X}'; +'\\u{'; +'\\u{zz}'; 'multi line'; "\\\\"; diff --git a/tests/string-double-quote/quoting.php b/tests/string-double-quote/quoting.php index eab1fee4b..38b4d41d1 100644 --- a/tests/string-double-quote/quoting.php +++ b/tests/string-double-quote/quoting.php @@ -25,6 +25,9 @@ '\u{aa}'; '\u{0000aa}'; '\u{9999}'; +'\u{%04X}'; +'\u{'; +'\u{zz}'; 'multi line'; '\\';