Skip to content

Commit

Permalink
- added exception-throwing check for document listener aka iterator: …
Browse files Browse the repository at this point in the history
…if it's not a function, js-yaml now throws an exception

- remove eslint unused-var patch used during development
  • Loading branch information
GerHobbelt committed Apr 15, 2019
1 parent 5f0285e commit c8c9ec7
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/js-yaml/loader.js
@@ -1,6 +1,6 @@
'use strict';

/*eslint-disable max-len,no-use-before-define,no-unused-vars*/
/*eslint-disable max-len,no-use-before-define*/

var common = require('./common');
var YAMLException = require('./exception');
Expand Down Expand Up @@ -949,7 +949,7 @@ function readBlockScalar(state, nodeIndent) {

function readBlockSequence(state, nodeIndent) {
var _line,
_pos,
//_pos,
_tag = state.tag,
_anchor = state.anchor,
_result = [],
Expand Down Expand Up @@ -987,7 +987,7 @@ function readBlockSequence(state, nodeIndent) {
}

_line = state.line;
_pos = state.position;
//_pos = state.position;
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
//addMetaInformation(state, _result, keyNode, _line, _pos);
_result.push(state.result);
Expand Down Expand Up @@ -1478,8 +1478,6 @@ function readDocument(state) {
var _position,
iterator,
doc,
index,
length,
directiveName,
directiveArgs,
hasDirectives = false,
Expand Down Expand Up @@ -1574,14 +1572,16 @@ function readDocument(state) {
iterator = state.documentListener;
var expectAnotherYamlChunk = false;
if (iterator) {
if (typeof iterator !== 'function') {
throwError(state, 'document listener (iterator) must be a FUNCTION or NULL, not a ' + typeof iterator);
}
expectAnotherYamlChunk = !!iterator(doc, state.documents.length - 1, state);
if (expectAnotherYamlChunk) {
skipSeparationSpace(state, true, -1);
}
}

if (state.position === state.lineStart && testDocumentSeparator(state)) {

if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
state.position += 3;
skipSeparationSpace(state, true, -1);
Expand Down Expand Up @@ -1651,11 +1651,8 @@ function load(input, options) {
}


function safeLoadAll(input, output, options) {
if (typeof output !== 'function') {
output = null;
}
return loadAll(input, output, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
function safeLoadAll(input, iterator, options) {
return loadAll(input, iterator, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
}


Expand Down

0 comments on commit c8c9ec7

Please sign in to comment.