mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
Fix CSS errors when using HTML escaped quotes
This commit is contained in:
@@ -198,6 +198,17 @@ function updateContent(c: EmbeddedRegion, content: string): string {
|
||||
if (!c.attributeValue && c.languageId === 'javascript') {
|
||||
return content.replace(`<!--`, `/* `).replace(`-->`, ` */`);
|
||||
}
|
||||
if (c.languageId === 'css') {
|
||||
const quoteEscape = /("|")/g;
|
||||
return content.replace(quoteEscape, (match, _, offset) => {
|
||||
const spaces = ' '.repeat(match.length - 1);
|
||||
const afterChar = content[offset + match.length];
|
||||
if (!afterChar || afterChar.includes(' ')) {
|
||||
return `${spaces}"`;
|
||||
}
|
||||
return `"${spaces}`;
|
||||
});
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,4 +128,11 @@ suite('HTML Embedded Support', () => {
|
||||
assertEmbeddedLanguageContent('<div onKeyUp=return\n/><script>foo();</script>', 'javascript', ' return;\n foo(); ');
|
||||
});
|
||||
|
||||
test('Script content - HTML escape characters', function (): any {
|
||||
assertEmbeddedLanguageContent('<div style="font-family: "Arial""></div>', 'css', ' __{font-family: " Arial "} ');
|
||||
assertEmbeddedLanguageContent('<div style="font-family: "Arial""></div>', 'css', ' __{font-family: " Arial "} ');
|
||||
assertEmbeddedLanguageContent('<div style="font-family: "Arial""></div>', 'css', ' __{font-family: " Arial "} ');
|
||||
assertEmbeddedLanguageContent('<div style="font-family:" Arial " "></div>', 'css', ' __{font-family: " Arial " } ');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user