From 2aa3b0ceeb76bc9bd5e4e4789d965cc483dba185 Mon Sep 17 00:00:00 2001 From: Aaron Dandy <404933+aarondandy@users.noreply.github.com> Date: Sat, 7 Dec 2024 14:51:25 -0800 Subject: [PATCH] Fixes argument parsing for escaped newlines (#1176) Co-authored-by: user --- lib/methods/template.js | 6 +++++- test/methods/template.js | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/methods/template.js b/lib/methods/template.js index 4bc462159c..6b7745ea3a 100644 --- a/lib/methods/template.js +++ b/lib/methods/template.js @@ -75,7 +75,11 @@ const splitByWhitespaces = (template, rawTemplate) => { templateStart = templateIndex + 1; } else if (rawCharacter === '\\') { const nextRawCharacter = rawTemplate[rawIndex + 1]; - if (nextRawCharacter === 'u' && rawTemplate[rawIndex + 2] === '{') { + if (nextRawCharacter === '\n') { + // Handles escaped newlines in templates + templateIndex -= 1; + rawIndex += 1; + } else if (nextRawCharacter === 'u' && rawTemplate[rawIndex + 2] === '{') { rawIndex = rawTemplate.indexOf('}', rawIndex + 3); } else { rawIndex += ESCAPE_LENGTH[nextRawCharacter] ?? 1; diff --git a/test/methods/template.js b/test/methods/template.js index c1efde9ca8..c67f536759 100644 --- a/test/methods/template.js +++ b/test/methods/template.js @@ -22,6 +22,14 @@ test('$ can use newlines and tab indentations', testScriptStdout, () => $`echo.j bar`, 'foo\nbar'); test('$ can use newlines and space indentations', testScriptStdout, () => $`echo.js foo bar`, 'foo\nbar'); +test('$ can use escaped newlines and space indentations', testScriptStdout, () => $`echo.js foo\ + bar`, 'foo\nbar'); +test('$ can use escaped newlines and inline tab indentations', testScriptStdout, () => $`echo.js foo\ + bar`, 'foo\nbar'); +test('$ can use escaped newlines and character escaped tab indentations', testScriptStdout, () => $`echo.js foo\ +\tbar`, 'foo\tbar'); +test('$ can use escaped newlines and character escaped newlines', testScriptStdout, () => $`echo.js foo\ +\n\nbar`, 'foo\n\nbar'); test('$ can use Windows newlines and tab indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n\tbar'), 'foo\nbar'); test('$ can use Windows newlines and space indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n bar'), 'foo\nbar'); test('$ does not ignore comments in expressions', testScriptStdout, () => $`echo.js foo