Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 96fc4c6

Browse files
committed
fix(oas3): handle internal YAML parser error
1 parent a3215ea commit 96fc4c6

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

packages/fury-adapter-oas3-parser/lib/parser/parseYAML.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ function parse(source, context) {
111111
if (error.problem) {
112112
const problem = error.problem.replace('\t', '\\t');
113113
message = `${problem}, ${error.context}`;
114-
} else {
114+
} else if (error.context) {
115115
message = error.context;
116+
} else {
117+
({ message } = error);
116118
}
117119

118120
const annotation = new namespace.elements.Annotation(
@@ -121,12 +123,14 @@ function parse(source, context) {
121123
);
122124

123125
const marker = error.context_mark || error.problem_mark;
124-
copySourceMap(
125-
marker,
126-
marker,
127-
annotation,
128-
namespace
129-
);
126+
if (marker) {
127+
copySourceMap(
128+
marker,
129+
marker,
130+
annotation,
131+
namespace
132+
);
133+
}
130134

131135
parseResult.push(annotation);
132136
return parseResult;

packages/fury-adapter-oas3-parser/test/unit/parser/parseYAML-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ describe('#parseYAML', () => {
3131

3232
expect(parseResult).contain.error('YAML Syntax: found character \\t that cannot start any token, while scanning for the next token').with.sourceMap([[14, 0]]);
3333
});
34+
35+
it('can handle internal YAML parser error', () => {
36+
// Protection against YAML parser bug where source map information isn't available
37+
// Particular case: https://github.com/connec/yaml-js/issues/46
38+
39+
const parseResult = parseYAML("key:\n key:\n key: 'x\nkey: 'string'", context);
40+
41+
expect(parseResult).to.be.instanceof(namespace.elements.ParseResult);
42+
expect(parseResult.errors.length).to.equal(1);
43+
44+
expect(parseResult).contain.error('YAML Syntax: logic failure');
45+
});
3446
});
3547

3648
it('can parse a string into a string element', () => {

0 commit comments

Comments
 (0)