From 4af74194f5e6964f0ce47aba42f9fa8a2389eb03 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Thu, 2 Nov 2023 18:36:02 -0700 Subject: [PATCH] fix: Carriage return in tag shorthand (#501) --- src/doc/directives.ts | 2 +- tests/doc/types.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/doc/directives.ts b/src/doc/directives.ts index add18fcd..1b152996 100644 --- a/src/doc/directives.ts +++ b/src/doc/directives.ts @@ -143,7 +143,7 @@ export class Directives { return verbatim } - const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/) as string[] + const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/s) as string[] if (!suffix) onError(`The ${source} tag has no suffix`) const prefix = this.tags[handle] if (prefix) { diff --git a/tests/doc/types.ts b/tests/doc/types.ts index 28f2180b..7646f303 100644 --- a/tests/doc/types.ts +++ b/tests/doc/types.ts @@ -112,6 +112,12 @@ describe('tags', () => { expect(doc.errors).toHaveLength(1) expect(doc.errors[0].message).toMatch('URIError') }) + + test('CR in tag shorthand (eemeli/yaml#501', () => { + const doc = parseDocument(': | !\r!') + const err = doc.errors.find(err => err.code === 'TAG_RESOLVE_FAILED') + expect(err).not.toBeFalsy() + }) }) test('eemeli/yaml#97', () => {