Skip to content

Commit

Permalink
fix: Do not throw error on malformed URI escape in tag (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
manunio authored Oct 14, 2023
1 parent a4d8569 commit 69d881c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/doc/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
6 changes: 6 additions & 0 deletions tests/doc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 69d881c

Please sign in to comment.