Skip to content

Fix build corruption of import.meta.env values containing $ when the env object is read directly - #18559

Merged
matthewp merged 1 commit into
mainfrom
factory/fix-18557
Oct 30, 2026
Merged

matthewp merged 1 commit into
mainfrom
factory/fix-18557

Conversation

@astro-factory

@astro-factory astro-factory Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Changes

Testing

  • Added unit tests in packages/astro/test/units/env/vite-plugin-import-meta-env.test.ts covering $$, $&, $`, and $' in env values accessed via the env object, verifying they are emitted verbatim rather than expanded.

Docs

  • No docs update needed; this is a bug fix with no API or configuration changes.

Closes #18557

@astro-factory astro-factory Bot added the fix verified Reporter confirmed the triage bot fix works label Oct 30, 2026
@changeset-bot

changeset-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

πŸ¦‹ Changeset detected

Latest commit: 6dc6a1f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

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-factory

astro-factory Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

astro-author owns this pull request

Factory'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
Status: waiting for feedback.

β€” astro-author (Factory persona)

@astro-factory
astro-factory Bot removed the request for review from astro-reviewer October 30, 2026 12:43

@astro-factory astro-factory Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.env values containing $ replacement sequences ($$, $&, $`, $') verbatim during astro build when code reads the env object directly (#18557). replaceDefine in packages/astro/src/env/vite-plugin-import-meta-env.ts:59 now passes a function to replaceAll. JavaScript does not expand $ patterns in a function's return value, so the serialized Object.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 uses MagicString.prepend and 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 in test/units/, imports from dist/, and uses node:test and 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.

@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Oct 30, 2026
@codspeed

codspeed Bot commented Oct 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 3 benchmarks have no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

βœ… 21 untouched benchmarks


Comparing factory/fix-18557 (6dc6a1f) with main (e023aba)

Open in CodSpeed

@matthewp
matthewp merged commit 10dae2f into main Oct 30, 2026
33 checks passed
@matthewp
matthewp deleted the factory/fix-18557 branch October 30, 2026 13:25
@astrobot-houston astrobot-houston mentioned this pull request Oct 30, 2026
dadezzz pushed a commit to dadezzz/university_notes that referenced this pull request Nov 6, 2026
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) | ![age](https://developer.mend.io/api/mc/badges/age/npm/astro/7.4.5?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/astro/7.4.4/7.4.5?slim=true) |

---

### 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

- [#&#8203;18558](withastro/astro#18558) [`fac3c50`](withastro/astro@fac3c50) Thanks [@&#8203;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

- [#&#8203;18559](withastro/astro#18559) [`10dae2f`](withastro/astro@10dae2f) Thanks [@&#8203;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`

- [#&#8203;18544](withastro/astro#18544) [`e3bec3d`](withastro/astro@e3bec3d) Thanks [@&#8203;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.

- [#&#8203;18520](withastro/astro#18520) [`e023aba`](withastro/astro@e023aba) Thanks [@&#8203;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-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix verified Reporter confirmed the triage bot fix works pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build corrupts import.meta.env values containing $ when a file reads the env object

2 participants