Skip to content

Commit 2aa3b0c

Browse files
aarondandyuser
andauthored
Fixes argument parsing for escaped newlines (#1176)
Co-authored-by: user <[email protected]>
1 parent c8cff27 commit 2aa3b0c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/methods/template.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ const splitByWhitespaces = (template, rawTemplate) => {
7575
templateStart = templateIndex + 1;
7676
} else if (rawCharacter === '\\') {
7777
const nextRawCharacter = rawTemplate[rawIndex + 1];
78-
if (nextRawCharacter === 'u' && rawTemplate[rawIndex + 2] === '{') {
78+
if (nextRawCharacter === '\n') {
79+
// Handles escaped newlines in templates
80+
templateIndex -= 1;
81+
rawIndex += 1;
82+
} else if (nextRawCharacter === 'u' && rawTemplate[rawIndex + 2] === '{') {
7983
rawIndex = rawTemplate.indexOf('}', rawIndex + 3);
8084
} else {
8185
rawIndex += ESCAPE_LENGTH[nextRawCharacter] ?? 1;

test/methods/template.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ test('$ can use newlines and tab indentations', testScriptStdout, () => $`echo.j
2222
bar`, 'foo\nbar');
2323
test('$ can use newlines and space indentations', testScriptStdout, () => $`echo.js foo
2424
bar`, 'foo\nbar');
25+
test('$ can use escaped newlines and space indentations', testScriptStdout, () => $`echo.js foo\
26+
bar`, 'foo\nbar');
27+
test('$ can use escaped newlines and inline tab indentations', testScriptStdout, () => $`echo.js foo\
28+
bar`, 'foo\nbar');
29+
test('$ can use escaped newlines and character escaped tab indentations', testScriptStdout, () => $`echo.js foo\
30+
\tbar`, 'foo\tbar');
31+
test('$ can use escaped newlines and character escaped newlines', testScriptStdout, () => $`echo.js foo\
32+
\n\nbar`, 'foo\n\nbar');
2533
test('$ can use Windows newlines and tab indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n\tbar'), 'foo\nbar');
2634
test('$ can use Windows newlines and space indentations', testScriptStdout, () => escapedCall('echo.js foo\r\n bar'), 'foo\nbar');
2735
test('$ does not ignore comments in expressions', testScriptStdout, () => $`echo.js foo

0 commit comments

Comments
 (0)