Skip to content

Commit

Permalink
fix: Malformed uri
Browse files Browse the repository at this point in the history
  • Loading branch information
manunio committed Oct 10, 2023
1 parent a4d8569 commit 5206398
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/doc/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
7 changes: 7 additions & 0 deletions tests/doc/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
})
})

0 comments on commit 5206398

Please sign in to comment.