Skip to content
Merged
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
20 changes: 4 additions & 16 deletions packages/angular/build/src/utils/server-rendering/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,8 @@ const MAIN_SERVER_OUTPUT_FILENAME = 'main.server.mjs';
* A mapping of unsafe characters to their escaped Unicode equivalents.
*/
const UNSAFE_CHAR_MAP: Record<string, string> = {
'<': '\\u003C',
'>': '\\u003E',
'/': '\\u002F',
'\\': '\\\\',
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\0': '\\0',
'\u2028': '\\u2028',
'\u2029': '\\u2029',
'`': '\\`',
'$': '\\$',
};

/**
Expand All @@ -46,7 +36,7 @@ const UNSAFE_CHAR_MAP: Record<string, string> = {
* @returns The escaped string where unsafe characters are replaced.
*/
function escapeUnsafeChars(str: string): string {
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029]/g, (c) => UNSAFE_CHAR_MAP[c]);
return str.replace(/[$`]/g, (c) => UNSAFE_CHAR_MAP[c]);
}

/**
Expand Down Expand Up @@ -149,9 +139,7 @@ export function generateAngularServerAppManifest(
file.path === INDEX_HTML_CSR ||
(inlineCriticalCss && file.path.endsWith('.css'))
) {
serverAssetsContent.push(
`['${file.path}', async () => ${escapeUnsafeChars(JSON.stringify(file.text))}]`,
);
serverAssetsContent.push(`['${file.path}', async () => \`${escapeUnsafeChars(file.text)}\`]`);
Copy link
Collaborator Author

@alan-agius4 alan-agius4 Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that using string literals here makes the other replacements unnecessary. However, the code scanner does not run on pull requests to confirm.

}
}

Expand Down