Skip to content

Commit

Permalink
Fixes argument parsing for escaped newlines (#1176)
Browse files Browse the repository at this point in the history
Co-authored-by: user <user@localhost.com>
  • Loading branch information
aarondandy and user authored Dec 7, 2024
1 parent c8cff27 commit 2aa3b0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/methods/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/methods/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2aa3b0c

Please sign in to comment.