Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/lib/meta-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function parseMetaTags(html: string, baseUrl: string): MetaTags {

// Extract <title>
const titleMatch = html.match(/<title[^>]*>(.*?)<\/title>/is);
if (titleMatch) tags.title = decodeEntities(titleMatch[1].trim());
if (titleMatch) tags.title = decodeEntities(titleMatch[1]).replace(/[ \t\n\r\f]+/g, ' ').trim();

// Extract meta tags
for (const tag of findTags(html, 'meta')) {
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/meta-fetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ describe('parseMetaTags', () => {
expect(tags.title).toBe('<Tom & Jerry "Show">');
});

it('collapses multiline indentation, internal tabs, and double spaces in title while preserving non-ASCII whitespace', () => {
const tags = parseMetaTags(
`<title>
Cutting\t\tcold starts in&nbsp;half with Fluid Compute
| Acme Blog
</title>`,
base,
);
expect(tags.title).toBe('Cutting cold starts in\u00a0half with Fluid Compute | Acme Blog');
});

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;">',
Expand Down
Loading