Skip to content

Commit

Permalink
[node] Tolerate repeated line terminators
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Oct 15, 2018
1 parent e8f2e63 commit 45b42e8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/agents/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class NodeAgent extends ConsoleAgent {
// [1] https://tc39.github.io/ecma262/#table-json-single-character-escapes
// [2] https://tc39.github.io/ecma262/#table-33
const escaped = JSON.stringify(code)
.replace('\u2028', '\\u2028')
.replace('\u2029', '\\u2029');
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');

// Because the input code may modify the global environment in ways that
// interfere with the normal operation of `eshost`, it must be run in a
Expand Down
43 changes: 43 additions & 0 deletions test/runify.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,49 @@ hosts.forEach(function(record) {
});
});

it('tolerates LINE SEPARATOR and PARAGRAPH SEPARATOR', function() {
var operations = [
'\u2028print("U+2028 once");',
'\u2029print("U+2029 once");',
'\u2028\u2029print("both U+2028 and U+2029");',
'\u2028\u2028print("U+2028 twice");',
'\u2029\u2029print("U+2029 twice");'
].map(function(src) { return agent.evalScript(src); });

return Promise.all(operations)
.then(function(results) {
assert.equal(results[0].stderr, '');
assert(
results[0].stdout.match(/^U\+2028 once\r?\n/),
'Unexpected stdout: ' + results[0].stdout
);

assert.equal(results[1].stderr, '');
assert(
results[1].stdout.match(/^U\+2029 once\r?\n/),
'Unexpected stdout: ' + results[1].stdout
);

assert.equal(results[2].stderr, '');
assert(
results[2].stdout.match(/^both U\+2028 and U\+2029\r?\n/),
'Unexpected stdout: ' + results[2].stdout
);

assert.equal(results[3].stderr, '');
assert(
results[3].stdout.match(/^U\+2028 twice\r?\n/),
'Unexpected stdout: ' + results[3].stdout
);

assert.equal(results[4].stderr, '');
assert(
results[4].stdout.match(/^U\+2029 twice\r?\n/),
'Unexpected stdout: ' + results[4].stdout
);
});
});

it('creates "optional" environments correctly (hostArgs)', function() {
// browsers are irrelevant to this test
if (['firefox', 'chrome', 'remote'].includes(type)) {
Expand Down

0 comments on commit 45b42e8

Please sign in to comment.