Skip to content

Commit

Permalink
Disallow completely empty nodes in flow collections
Browse files Browse the repository at this point in the history
fix #321
  • Loading branch information
rlidwka committed Dec 11, 2020
1 parent b1cc0e9 commit adfee17
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Astral characters are no longer encoded by dump/safeDump, #587.
- "duplicate mapping key" exception now points at the correct column, #452.
- Extra commas in flow collections (e.g. `[foo,,bar]`) now throw an exception
instead of producing null, #321.
- Removed `bower.json`.


Expand Down
3 changes: 3 additions & 0 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ function readFlowCollection(state, nodeIndent) {
return true;
} else if (!readNext) {
throwError(state, 'missed comma between flow collection entries');
} else if (ch === 0x2C/* , */) {
// "flow collection entries can never be completely empty", as per YAML 1.2, section 7.4
throwError(state, "expected the node content, but found ','");
}

keyTag = keyNode = valueNode = null;
Expand Down
19 changes: 19 additions & 0 deletions test/issues/0321.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';


const assert = require('assert');
const yaml = require('../../');


it('Should throw exception on extra comma in flow mappings', function () {
assert.throws(function () {
yaml.load('[foo, bar,, baz]');
}, /expected the node content, but found ','/);

assert.throws(function () {
yaml.load('{foo, bar,, baz}');
}, /expected the node content, but found ','/);

// empty key is allowed here
assert.deepStrictEqual(yaml.load('{foo,: bar}'), { foo: null, null: 'bar' });
});

0 comments on commit adfee17

Please sign in to comment.