mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
Don't double escape metadata (#8296)
Before this PR, source code in the `<meta name="description">` and `<meta property="og:description">` tags would be doubly escaped, leading to html escaped code showing up in link previews. Examples: Discord: <img width="465" height="167" alt="discord" src="https://github.com/user-attachments/assets/d2f867e6-f724-4177-8f1d-17986d13343f" /> Akkoma:  This fixes it by removing one layer of escaping.
This commit is contained in:
@@ -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) {
|
filterCode(req: express.Request, code: string, lang: Language) {
|
||||||
let lines = code.split('\n');
|
let lines = code.split('\n');
|
||||||
if (lang.previewFilter !== null) {
|
if (lang.previewFilter !== null) {
|
||||||
lines = lines.filter(line => !lang.previewFilter || !lang.previewFilter.test(line));
|
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) {
|
getMetaDataFromLink(req: express.Request, link: ExpandedShortLink | null, config: any) {
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ describe('Basic unfurls', () => {
|
|||||||
const res = await prom;
|
const res = await prom;
|
||||||
expect(res.metadata).toEqual({
|
expect(res.metadata).toEqual({
|
||||||
ogDescription:
|
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<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',
|
||||||
ogTitle: 'Compiler Explorer - C++',
|
ogTitle: 'Compiler Explorer - C++',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user