Skip to content

Commit

Permalink
fix(@angular/build): incomplete string escaping or encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 committed Sep 27, 2024
1 parent 0a4ef30 commit 87a90af
Showing 1 changed file with 4 additions and 16 deletions.
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)}\`]`);
}
}

Expand Down

0 comments on commit 87a90af

Please sign in to comment.