Repository navigation
Fix build corruption of import.meta.env values containing $ when the env object is read directly - #18559
Conversation
β¦is inlined in build
π¦ Changeset detectedLatest commit: 6dc6a1f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
astro-author owns this pull requestFactory's code author persona works on this branch when a maintainer or Factory's reviewer requests changes, or when checks fail: it pushes follow-up commits, replies to review threads, and asks for another review. It never merges. Unassign astro-author to take the pull request back; reassign it to start a fresh budget. Rounds used: 0 of 5 β astro-author (Factory persona) |
There was a problem hiding this comment.
Verdict: approved. No blocking findings remain.
GitHub doesn't let Factory approve a pull request it opened, so this verdict is recorded as a comment.
Findings
No findings.
Merge Requirement Assessment
Status: satisfied
- Inline
import.meta.envvalues containing$replacement sequences ($$,$&,$`,$') verbatim duringastro buildwhen code reads the env object directly (#18557).replaceDefineinpackages/astro/src/env/vite-plugin-import-meta-env.ts:59now passes a function toreplaceAll. JavaScript does not expand$patterns in a function's return value, so the serializedObject.assign(import.meta.env,{...})replacement is inserted exactly as written. The marker is the only search string and is a fixed literal, so this change cannot affect anything else. The dev path usesMagicString.prependand never had this problem. - Regression coverage. The new unit test puts all four sequences in one value and reads the env object through destructuring in a build transform. It then checks that the emitted code contains
SECRET:${JSON.stringify(value)}. Without the fix,$$would collapse to$and$&would expand to the marker, so the assertion would fail. The test sits intest/units/, imports fromdist/, and usesnode:testand the existing fixture helper, following repository conventions.
Review Status
Verdict: ready to merge based on static review
Context: PR #18559 plus linked issue #18557 (from the PR description)
Scope: PR base e023abac912d7cb6af2b9fb5107ef5dabc667096 to head 6dc6a1fef7d0d7663390548544a6c53391207be9 (3 files).
Changeset: present and covers astro (patch).
Limitations: I did not fetch the linked issue body separately; requirements come from the PR description.
Validation: Static review only; no project code, tests, builds, or checks were run.
GitHub context: collected
Git scope: PR base/head verified
This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.
Merging this PR will not alter performance1 warning, 1 note
Comparing |
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`7.4.4` β `7.4.5`](https://renovatebot.com/diffs/npm/astro/7.4.4/7.4.5) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v7.4.5`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#745) [Compare Source](https://github.com/withastro/astro/compare/astro@7.4.4...astro@7.4.5) ##### Patch Changes - [#​18558](withastro/astro#18558) [`fac3c50`](withastro/astro@fac3c50) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes `astro dev status` and other background server commands deleting the lock file of a running dev or preview server when run from a sandbox or as another user that is not permitted to signal its process - [#​18559](withastro/astro#18559) [`10dae2f`](withastro/astro@10dae2f) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes `import.meta.env` values containing `$` sequences (such as `$$` or `$&`) being corrupted in `astro build` when server code reads the `import.meta.env` object directly, for example with `const { MY_SECRET } = import.meta.env` - [#​18544](withastro/astro#18544) [`e3bec3d`](withastro/astro@e3bec3d) Thanks [@​skezo](https://github.com/skezo)! - Fixes request paths with invalid percent-encoding (e.g. `/%C0%AF` or a bare `%`) being logged as an `Invalid URL encoding` error and routed with the undecoded path. These requests now return a `400`, the same as a path that is encoded too many times. - [#​18520](withastro/astro#18520) [`e023aba`](withastro/astro@e023aba) Thanks [@​matthewp](https://github.com/matthewp)! - Makes rendering of string tag names stricter and consistent across `.astro` dynamic tags, JSX, and MDX. Only the leading part of the string that is a valid element name is rendered, so characters such as `/` or `=` can no longer change the generated markup. A string that does not start with a valid element name (for example `'!--'` or `''`) now throws an error instead of producing invalid HTML. </details> --- ### Configuration π **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) π¦ **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. π **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yMTYuNCIsInVwZGF0ZWRJblZlciI6IjQ0LjIxNi40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
Changes
import.meta.envvalues containing$replacement sequences ($$,$&,$`,$') are now inlined correctly duringastro buildwhen code reads the env object directly (e.g.const env = import.meta.envor destructuring). Previously,String.prototype.replaceAllinterpreted those sequences as replacement patterns, silently corrupting values (e.g.pa$$ssβpa$ss) or crashing the build with aPARSE_ERROR.replaceAll(marker, () => replacementMarkers[marker])β so the env string is treated as a literal. This is the same pattern used in Fix corruptedastro:env/servermodule when env vars contain$replacement patternsΒ #18330 and Fix redirect targets when a param value contains a$replacement patternΒ #18002 for related call sites in the same codebase.Testing
packages/astro/test/units/env/vite-plugin-import-meta-env.test.tscovering$$,$&,$`, and$'in env values accessed via the env object, verifying they are emitted verbatim rather than expanded.Docs
Closes #18557