From 63233d36ae71d13ca15a69441e9645dccc77fccb Mon Sep 17 00:00:00 2001 From: Agustin Mendez Date: Mon, 5 Sep 2016 12:36:12 -0300 Subject: [PATCH] It dies on malformed %YAML directive What is the FIXME on line 186? Why is line 216 commented? Example of breaking code: ```javascript const y = require('yaml-ast-parser'); y.loadAll( `%YAML 12 --- a: 123`, function(){ console.log(require('util').inspect(arguments, false, 10, true)) }) TypeError: Cannot read property '1' of null ``` --- src/loader.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/loader.ts b/src/loader.ts index 087d18a..fb75882 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -245,20 +245,20 @@ var directiveHandlers = { if (null === match) { throwError(state, 'ill-formed argument of the YAML directive'); - } - - major = parseInt(match[1], 10); - minor = parseInt(match[2], 10); - - if (1 !== major) { - throwError(state, 'found incompatible YAML document (version 1.2 is required)'); - } - - state.version = args[0]; - state.checkLineBreaks = (minor < 2); - - if (2 !== minor) { - throwError(state, 'found incompatible YAML document (version 1.2 is required)'); + } else { + major = parseInt(match[1], 10); + minor = parseInt(match[2], 10); + + if (1 !== major) { + throwError(state, 'found incompatible YAML document (version 1.2 is required)'); + } + + state.version = args[0]; + state.checkLineBreaks = (minor < 2); + + if (2 !== minor) { + throwError(state, 'found incompatible YAML document (version 1.2 is required)'); + } } },