diff --git a/src/doc/directives.ts b/src/doc/directives.ts index 4978c07f..add18fcd 100644 --- a/src/doc/directives.ts +++ b/src/doc/directives.ts @@ -146,7 +146,14 @@ export class Directives { const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/) as string[] if (!suffix) onError(`The ${source} tag has no suffix`) const prefix = this.tags[handle] - if (prefix) return prefix + decodeURIComponent(suffix) + if (prefix) { + try { + return prefix + decodeURIComponent(suffix) + } catch (error) { + onError(String(error)) + return null + } + } if (handle === '!') return source // local tag onError(`Could not resolve tag: ${source}`) diff --git a/tests/doc/types.ts b/tests/doc/types.ts index c03668be..28f2180b 100644 --- a/tests/doc/types.ts +++ b/tests/doc/types.ts @@ -106,6 +106,12 @@ describe('tags', () => { expect(doc.errors[0].code).toBe('MISSING_CHAR') }) } + + test('malformed URI (eemeli/yaml#498)', () => { + const doc = parseDocument('!!%ee 0') + expect(doc.errors).toHaveLength(1) + expect(doc.errors[0].message).toMatch('URIError') + }) }) test('eemeli/yaml#97', () => {