From 4bcd8e2b529de3f77a2f56a14629cfd69578a14c Mon Sep 17 00:00:00 2001 From: nrdmn Date: Tue, 16 Dec 2025 00:50:07 +0100 Subject: [PATCH] Don't double escape metadata (#8296) Before this PR, source code in the `` and `` tags would be doubly escaped, leading to html escaped code showing up in link previews. Examples: Discord: discord Akkoma: ![akkoma](https://github.com/user-attachments/assets/22b11c48-1bef-4424-a70a-3948213a8354) This fixes it by removing one layer of escaping. --- lib/handlers/route-api.ts | 6 +----- test/unfurl-tests.ts | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/handlers/route-api.ts b/lib/handlers/route-api.ts index 243cb0698..e07bb187d 100644 --- a/lib/handlers/route-api.ts +++ b/lib/handlers/route-api.ts @@ -225,16 +225,12 @@ export class RouteAPI { }); } - escapeLine(req: express.Request, line: string) { - return line.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'); - } - filterCode(req: express.Request, code: string, lang: Language) { let lines = code.split('\n'); if (lang.previewFilter !== null) { lines = lines.filter(line => !lang.previewFilter || !lang.previewFilter.test(line)); } - return lines.map(line => this.escapeLine(req, line)).join('\n'); + return lines.join('\n'); } getMetaDataFromLink(req: express.Request, link: ExpandedShortLink | null, config: any) { diff --git a/test/unfurl-tests.ts b/test/unfurl-tests.ts index bfcd02d4f..f91f90979 100644 --- a/test/unfurl-tests.ts +++ b/test/unfurl-tests.ts @@ -106,7 +106,7 @@ describe('Basic unfurls', () => { const res = await prom; expect(res.metadata).toEqual({ ogDescription: - '\ntemplate<typename T>\nconcept TheSameAndAddable = requires(T a, T b) {\n {a+b} -> T;\n};\n\ntemplate<TheSameAndAddable T>\nT sum(T x, T y) {\n return x + y;\n}\n\n#include <string>\n\nint main() {\n int z = 0;\n int w;\n\n return sum(z, w);\n}\n', + '\ntemplate\nconcept TheSameAndAddable = requires(T a, T b) {\n {a+b} -> T;\n};\n\ntemplate\nT sum(T x, T y) {\n return x + y;\n}\n\n#include \n\nint main() {\n int z = 0;\n int w;\n\n return sum(z, w);\n}\n', ogTitle: 'Compiler Explorer - C++', }); });