Skip to content

Fix YAML JSON Schema files starting with %YAML 1.x#1073

Merged
datho7561 merged 1 commit intoredhat-developer:mainfrom
dlech:fix-yaml-schema-detection
May 26, 2025
Merged

Fix YAML JSON Schema files starting with %YAML 1.x#1073
datho7561 merged 1 commit intoredhat-developer:mainfrom
dlech:fix-yaml-schema-detection

Conversation

@dlech
Copy link
Contributor

@dlech dlech commented May 14, 2025

What does this PR do?

Fix a bug where YAML files containing a JSON Schema that start with %YAML 1.x or a comment that contains a number would fail to to be parsed.

This is caused by the fact that the JSON Schema parser would contain the number, e.g. 1.2 as the value of unresolvedJsonSchema.schema and so the test for === undefined would fail. This would cause the error from the JSON parser to be returned instead of trying to parse the file as a YAML file.

To work around this, also check if unresolvedJsonSchema.schema is a number. It if is, it clearly was not a JSON Schema and so we can safely try to parse the file as a YAML file.

What issues does this PR fix or reference?

Fixes: #922

Is it tested? How?

The modified test failed before the code change and passes after.

@coveralls
Copy link

coveralls commented May 26, 2025

Coverage Status

coverage: 83.873% (+0.002%) from 83.871%
when pulling cb82e0d on dlech:fix-yaml-schema-detection
into 6424ff6 on redhat-developer:main.

Copy link
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes the bug for me. Thanks!

Fix a bug where YAML files containing a JSON Schema that start with
%YAML 1.x or a comment that contains a number would fail to to be parsed.

This is caused by the fact that the JSON Schema parser would contain the
number, e.g. 1.2 as the value of `unresolvedJsonSchema.schema` and so
the test for `=== undefined` would fail. This would cause the error from
the JSON parser to be returned instead of trying to parse the file as a
YAML file.

To work around this, also check if `unresolvedJsonSchema.schema` is a
number. It if is, it clearly was not a JSON Schema and so we can safely
try to parse the file as a YAML file.

Fixes: redhat-developer#922
Signed-off-by: David Lechner <dlechner@baylibre.com>
@datho7561 datho7561 force-pushed the fix-yaml-schema-detection branch from 75a3dd9 to cb82e0d Compare May 26, 2025 17:21
@datho7561 datho7561 merged commit c94fa43 into redhat-developer:main May 26, 2025
4 checks passed
@dlech dlech deleted the fix-yaml-schema-detection branch May 26, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Numbers in comments

3 participants