diff --git a/src/doc/directives.ts b/src/doc/directives.ts index 4978c07f..06fc5925 100644 --- a/src/doc/directives.ts +++ b/src/doc/directives.ts @@ -146,7 +146,13 @@ 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('Failed to decode suffix') + } + } if (handle === '!') return source // local tag onError(`Could not resolve tag: ${source}`) diff --git a/tests/doc/parse.ts b/tests/doc/parse.ts index a40ac414..31dc0b6a 100644 --- a/tests/doc/parse.ts +++ b/tests/doc/parse.ts @@ -819,3 +819,10 @@ describe('CRLF line endings', () => { expect(res).toBe('foo bar') }) }) + +describe('Failed to decode suffix', () => { + test('rise in parse for malformed uri', () => { + const data = `[!!eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeJJJJJJJeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeebooleaeeeeeeeeeee-eeeeeeeee%eeeeeeeeeeeee[` + expect(() => YAML.parse(data)).toThrow(/Failed to decode suffix/) + }) +})