Skip to content

Commit 69d881c

Browse files
authored
fix: Do not throw error on malformed URI escape in tag (#498)
1 parent a4d8569 commit 69d881c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/doc/directives.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ export class Directives {
146146
const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/) as string[]
147147
if (!suffix) onError(`The ${source} tag has no suffix`)
148148
const prefix = this.tags[handle]
149-
if (prefix) return prefix + decodeURIComponent(suffix)
149+
if (prefix) {
150+
try {
151+
return prefix + decodeURIComponent(suffix)
152+
} catch (error) {
153+
onError(String(error))
154+
return null
155+
}
156+
}
150157
if (handle === '!') return source // local tag
151158

152159
onError(`Could not resolve tag: ${source}`)

tests/doc/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ describe('tags', () => {
106106
expect(doc.errors[0].code).toBe('MISSING_CHAR')
107107
})
108108
}
109+
110+
test('malformed URI (eemeli/yaml#498)', () => {
111+
const doc = parseDocument('!!%ee 0')
112+
expect(doc.errors).toHaveLength(1)
113+
expect(doc.errors[0].message).toMatch('URIError')
114+
})
109115
})
110116

111117
test('eemeli/yaml#97', () => {

0 commit comments

Comments
 (0)