diff --git a/src/lib/meta-fetcher.ts b/src/lib/meta-fetcher.ts index 63cd4d0..347dfbc 100644 --- a/src/lib/meta-fetcher.ts +++ b/src/lib/meta-fetcher.ts @@ -181,6 +181,10 @@ const NAMED_ENTITIES: Record = { quot: '"', apos: "'", nbsp: '\u00a0', + AMP: '&', + LT: '<', + GT: '>', + QUOT: '"', }; function decodeEntities(str: string): string { diff --git a/tests/lib/meta-fetcher.test.ts b/tests/lib/meta-fetcher.test.ts index 589e44c..fee4538 100644 --- a/tests/lib/meta-fetcher.test.ts +++ b/tests/lib/meta-fetcher.test.ts @@ -47,6 +47,22 @@ describe('parseMetaTags', () => { expect(tags.title).toBe("Tom & Jerry's"); }); + it('decodes uppercase named entities &, <, >, and "', () => { + const tags = parseMetaTags( + '<Tom & Jerry "Show">', + base, + ); + expect(tags.title).toBe(''); + }); + + it('does not decode uppercase or mixed-case entities that are not valid in HTML', () => { + const tags = parseMetaTags( + '', + base, + ); + expect(tags.description).toBe('&APOS; &NBSP; &Amp;'); + }); + it('parses unquoted meta attributes', () => { const tags = parseMetaTags('', base); expect(tags.twitterCard).toBe('summary_large_image');