Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/meta-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ const NAMED_ENTITIES: Record<string, string> = {
quot: '"',
apos: "'",
nbsp: '\u00a0',
AMP: '&',
LT: '<',
GT: '>',
QUOT: '"',
};

function decodeEntities(str: string): string {
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/meta-fetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ describe('parseMetaTags', () => {
expect(tags.title).toBe("Tom & Jerry's");
});

it('decodes uppercase named entities &AMP;, &LT;, &GT;, and &QUOT;', () => {
const tags = parseMetaTags(
'<title>&LT;Tom &AMP; Jerry &QUOT;Show&QUOT;&GT;</title>',
base,
);
expect(tags.title).toBe('<Tom & Jerry "Show">');
});

it('does not decode uppercase or mixed-case entities that are not valid in HTML', () => {
const tags = parseMetaTags(
'<meta name="description" content="&APOS; &NBSP; &Amp;">',
base,
);
expect(tags.description).toBe('&APOS; &NBSP; &Amp;');
});

it('parses unquoted meta attributes', () => {
const tags = parseMetaTags('<meta name=twitter:card content="summary_large_image">', base);
expect(tags.twitterCard).toBe('summary_large_image');
Expand Down
Loading