mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 07:04:04 -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) {
|
||||
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) {
|
||||
|
||||
@@ -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<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++',
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user