Skip to content

Commit

Permalink
fix(markdown): increase robustness when using format as a property name
Browse files Browse the repository at this point in the history
checks that format is a string, otherwise ignores it

fixes #198
  • Loading branch information
trieloff committed Jan 14, 2020
1 parent 85ca0e9 commit cda0bec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,14 @@ function build({
constraints.push(paragraph([link(`https://regexr.com/?expression=${encodeURIComponent(schema[keyword`pattern`])}`, i18n`try regular expression with regexr.com`, text(i18n`try pattern`))]));
}
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.7.3
if (schema.format && formats[schema.format]) {
if (schema.format && typeof schema.format === 'string' && formats[schema.format]) {
constraints.push(paragraph([
strong(text(formats[keyword([schema.format])].label)),
text(': '),
text(formats[schema.format].text),
link(formats[schema.format].speclink, i18n`check the specification`, text(formats[schema.format].specname)),
]));
} else if (schema.format) {
} else if (schema.format && typeof schema.format === 'string') {
constraints.push(paragraph([strong(text(i18n`unknown format`)), text(': '), text(i18n`the value of this string must follow the format: `), inlineCode(String(schema.format))]));
}

Expand Down
4 changes: 2 additions & 2 deletions test/markdownBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ describe('Testing Markdown Builder: format', () => {
});

it('Format Schema looks OK', () => {
assertMarkdown(results.properties)
.fuzzy`defined in: [Meta](meta-definitions-meta-properties-title.md "https://ns.adobe.com/helix/pipeline/meta#/definitions/meta/properties/title")`;
assertMarkdown(results.format)
.fuzzy`Formatting used to display the date.`;
});
});

Expand Down

0 comments on commit cda0bec

Please sign in to comment.