-
-
Notifications
You must be signed in to change notification settings - Fork 239
Closed
Description
Library: @apidevtools/json-schema-ref-parser
Version: 14.0.1
Environment: Node.js 24.3.0
Description
Parsing a YAML file containing a !!binary tag fails with:
Error: unknown tag !<tag:yaml.org,2002:binary>
This happens at the parse(yamlFile) step.
Example schema
Person:
properties:
email:
type: string
pattern: !!binary |-
W15cdFxyXG5cdlxmXVteQF0qQFteXC5dK1wuLipbXlx0XHJcblwgC1xmXQ==
Actual Result
Error: unknown tag !<tag:yaml.org,2002:binary>
Expected Result
The parser should correctly handle YAML !!binary tags (at least when the decoded data is a string, e.g., regex patterns).
Workaround
You can override the YAML parser plugin to use js-yaml’s default load:
/**
* The difference from the original plugin is that we don't use config { schema: JSON_SCHEMA }
* In the original plugin yaml.load(data, { schema: JSON_SCHEMA }) causes an "unknown tag !!binary" error.
*/
const safeLoadYamlPlugin: Plugin = {
name: 'safeLoadYamlPlugin',
order: 200,
allowEmpty: true,
canParse: [".yaml", ".yml", ".json"],
async parse(file: FileInfo) {
let data = file.data;
if (Buffer.isBuffer(data)) {
data = data.toString();
}
if (typeof data === "string") {
try {
return yaml.load(data);
} catch (e: any) {
throw new ParserError(e?.message || "Parser Error", file.url);
}
} else {
return data;
}
}
};
parse("example.yaml", {
yaml: safeLoadYamlPlugin
});
Metadata
Metadata
Assignees
Labels
No labels