Skip to content

[Backport 20.3.X] fix(@angular/build): serialize server manifest asset paths - #34510

Open
SkyZeroZx wants to merge 1 commit into
angular:20.3.xfrom
SkyZeroZx:fix/server-manifest-serialization-20.3.x
Open

SkyZeroZx wants to merge 1 commit into
angular:20.3.xfrom
SkyZeroZx:fix/server-manifest-serialization-20.3.x

Conversation

@SkyZeroZx

Copy link
Copy Markdown
Contributor

Backport of #34493

Serialize the values embedded in the generated server manifests with
`JSON.stringify`, so a prerendered route such as `ssg/customer's-choice`
no longer produces an invalid manifest.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that asset paths, base hrefs, and other manifest values are safely serialized using JSON.stringify instead of direct interpolation, preventing syntax errors when these values contain JavaScript string delimiters like single quotes. Unit and end-to-end tests have been added to verify this behavior. Feedback is provided on the test helper evaluateManifest to use a more robust regular expression when replacing 'export default', preventing accidental replacements if that substring appears within serialized content.

Comment on lines +21 to +23
function evaluateManifest(manifestContent: string): unknown {
return new Function(manifestContent.replace('export default', 'return'))();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using a simple string replacement manifestContent.replace('export default', 'return') will replace the first occurrence of 'export default'. If any serialized asset paths, routes, or other content in the manifest happen to contain the substring 'export default', the replacement will occur there instead of the actual export statement, leading to syntax or evaluation errors. Using a regular expression with the multiline flag (/m) and anchoring to the start of the line (^) makes this replacement much more robust.

  function evaluateManifest(manifestContent: string): unknown {\n    return new Function(manifestContent.replace(/^\\s*export default/m, 'return'))();\n  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant