Skip to content

Commit

Permalink
Allow non-printable characters inside quoted string literals.
Browse files Browse the repository at this point in the history
Fixed issue nodeca#192.
  • Loading branch information
a-rodin committed Nov 21, 2015
1 parent 73c7421 commit a14d85c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lib/js-yaml/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ function captureSegment(state, start, end, checkJson) {
throwError(state, 'expected valid JSON character');
}
}
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
throwError(state, 'the stream contains non-printable characters');
}

state.result += _result;
Expand Down Expand Up @@ -1522,10 +1524,6 @@ function loadDocuments(input, options) {

var state = new State(input, options);

if (PATTERN_NON_PRINTABLE.test(state.input)) {
throwError(state, 'the stream contains non-printable characters');
}

// Use 0 as string terminator. That significantly simplifies bounds check.
state.input += '\0';

Expand Down
5 changes: 4 additions & 1 deletion test/units/character-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ test('Forbid lone surrogates', function () {
assert.throws(function () { yaml.load('\udc00\ud800'); }, yaml.YAMLException);
});

test.skip('Allow non-printable characters inside quoted scalars', function () {
test('Allow non-printable characters inside quoted scalars', function () {
assert.strictEqual(yaml.load('"\x7f\x9f\udc00\ud800"'), '\x7f\x9f\udc00\ud800');
});

test('Forbid control sequences inside quoted scalars', function () {
assert.throws(function () { yaml.load('"\x03"'); }, yaml.YAMLException);
});

0 comments on commit a14d85c

Please sign in to comment.