Skip to content

fix(config): compare env var offsets in rune space when skipping comments - #3856

Merged
Yuan325 merged 2 commits into
googleapis:mainfrom
49EHyeon42:fix-config-env-rune-offset
Aug 21, 2026
Merged

Yuan325 merged 2 commits into
googleapis:mainfrom
49EHyeon42:fix-config-env-rune-offset

Conversation

@49EHyeon42

Copy link
Copy Markdown
Contributor

Description

parseEnv skipped some ${VAR} placeholders that were not inside comments,
leaving the literal ${VAR} text as the configuration value with no error or
warning. It happened when the config contained comments with multi-byte
characters, so a config could start failing after only a comment was edited.

The offsets came from two different coordinate spaces. re.FindAllStringSubmatchIndex
returns byte offsets, while token.Position.Offset from the go-yaml lexer is a
1-based rune offset: the scanner converts its input with []rune(text) and
starts counting at 1. For input containing multi-byte characters the two drift
apart, and once the drift is large enough a placeholder that sits outside any
comment gets an offset that falls inside a later comment token's range.

The range end had the same problem, since it was computed with len(t.Origin)
in bytes. Origin also carries the indentation that precedes the # while
Position.Offset already points at the #, so the range could extend past the
end of the comment.

This is a regression from #3807.

Solution

  • Track a 1-based rune offset alongside the byte offset at the call site, so
    both sides of the comparison use the lexer's coordinate space. Matches are
    ordered, so the input is still only walked once.
  • Measure the comment length in runes, from the #, so the range covers exactly
    the comment.
  • Add two TestParseEnv cases: one asserting placeholders after a multi-byte
    comment are substituted, and one asserting placeholders inside a multi-byte
    comment are still skipped.

Verified that the new cases fail without the change and pass with it, and that
the existing cmd/internal tests, gofmt and go vet are clean.

PR Checklist

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure you have manually reviewed the entire diff before requesting a
    review
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #3855

…ents

Placeholder offsets came from the regexp as byte offsets while the go-yaml
lexer reports token positions as 1-based rune offsets, so for input with
multi-byte characters the two drifted apart and placeholders outside any
comment were skipped. The range end also used the byte length of Origin,
which includes the indentation preceding the "#".

Track a 1-based rune offset at the call site and measure the comment length
in runes from the "#". Add regression cases for placeholders after and
inside multi-byte comments.
@49EHyeon42
49EHyeon42 requested a review from a team as a code owner August 21, 2026 04:43

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

Copy link
Copy Markdown
Contributor

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 fixes an issue where environment variable substitution in YAML configuration files behaves incorrectly when comments contain multi-byte characters. It addresses this by tracking 1-based rune offsets instead of raw byte offsets when mapping regexp matches to lexer token positions, and by correctly calculating the rune length of comments. Unit tests have been added to verify this behavior. There are no review comments, so no additional feedback is provided.

@Yuan325

Yuan325 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

/gcbrun

@Yuan325 Yuan325 added the release candidate Use label to signal PR should be included in the next release. label Aug 21, 2026
@Yuan325
Yuan325 enabled auto-merge (squash) August 21, 2026 05:00
@Yuan325
Yuan325 merged commit 2e76934 into googleapis:main Aug 21, 2026
21 checks passed
Yuan325 added a commit that referenced this pull request Aug 27, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.10.0](v1.9.0...v1.10.0)
(2026-08-27)


### Features

* **falkordb:** Add FalkorDB source and tools
([#3692](#3692))
([a94702c](a94702c))
* **firestore-mongodb:** Add firestore-execute-mql and firestore-get-…
([#3826](#3826))
([4a85d75](4a85d75))
* **mcp:** Add Secure Parameters support as Toolbox experimental
extension
([#3394](#3394))
([9750d2d](9750d2d))
* **server/mcp:** Support com.google.cloud/toolbox.v1 extension in
v20260728
([#3801](#3801))
([f4f7da6](f4f7da6))
* **skill:** Add fix-failing-tests skill for mcp-toolbox
([#3821](#3821))
([168e69c](168e69c))
* **sources:** Support native read-only mode and dynamic tool
annotations
([#3872](#3872))
([c257022](c257022)),
refs [#3615](#3615)
[#3816](#3816)
[#3618](#3618)
[#3851](#3851)
[#3619](#3619)
[#3617](#3617)
* **tool/mongodb:** Allow collection to be specified at runtime
([#3715](#3715))
([7626eaf](7626eaf))


### Bug Fixes

* **cloud-storage:** Resolve symlinks when enforcing local path
boundaries
([#3810](#3810))
([c2ada64](c2ada64))
* **config:** Compare env var offsets in rune space when skipping
comments
([#3856](#3856))
([2e76934](2e76934))
* Merge prebuilt tools when reloading custom config
([#3864](#3864))
([5a6d865](5a6d865))
* Normalize postgres UUIDs to strings
([#3806](#3806))
([3b02f1d](3b02f1d))
* **postgres:** Filter background processes in
postgres-list-active-queries
([#3885](#3885))
([3d9e62a](3d9e62a))
* **test/alloydbainl:** Use explicit SQL alias prompts to stabilize AI…
([#3877](#3877))
([50e45ed](50e45ed))
* **tests:** Prevent resource leaks by using context.WithoutCancel
([#3849](#3849))
([f97a4f9](f97a4f9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Yuan Teoh <[email protected]>
github-actions Bot pushed a commit that referenced this pull request Aug 27, 2026
🤖 I have created a release *beep* *boop*
---

##
[1.10.0](v1.9.0...v1.10.0)
(2026-08-27)

### Features

* **falkordb:** Add FalkorDB source and tools
([#3692](#3692))
([a94702c](a94702c))
* **firestore-mongodb:** Add firestore-execute-mql and firestore-get-…
([#3826](#3826))
([4a85d75](4a85d75))
* **mcp:** Add Secure Parameters support as Toolbox experimental
extension
([#3394](#3394))
([9750d2d](9750d2d))
* **server/mcp:** Support com.google.cloud/toolbox.v1 extension in
v20260728
([#3801](#3801))
([f4f7da6](f4f7da6))
* **skill:** Add fix-failing-tests skill for mcp-toolbox
([#3821](#3821))
([168e69c](168e69c))
* **sources:** Support native read-only mode and dynamic tool
annotations
([#3872](#3872))
([c257022](c257022)),
refs [#3615](#3615)
[#3816](#3816)
[#3618](#3618)
[#3851](#3851)
[#3619](#3619)
[#3617](#3617)
* **tool/mongodb:** Allow collection to be specified at runtime
([#3715](#3715))
([7626eaf](7626eaf))

### Bug Fixes

* **cloud-storage:** Resolve symlinks when enforcing local path
boundaries
([#3810](#3810))
([c2ada64](c2ada64))
* **config:** Compare env var offsets in rune space when skipping
comments
([#3856](#3856))
([2e76934](2e76934))
* Merge prebuilt tools when reloading custom config
([#3864](#3864))
([5a6d865](5a6d865))
* Normalize postgres UUIDs to strings
([#3806](#3806))
([3b02f1d](3b02f1d))
* **postgres:** Filter background processes in
postgres-list-active-queries
([#3885](#3885))
([3d9e62a](3d9e62a))
* **test/alloydbainl:** Use explicit SQL alias prompts to stabilize AI…
([#3877](#3877))
([50e45ed](50e45ed))
* **tests:** Prevent resource leaks by using context.WithoutCancel
([#3849](#3849))
([f97a4f9](f97a4f9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Yuan Teoh <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
mcp-toolbox 1.10.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## [1.10.0](googleapis/mcp-toolbox@v1.9.0...v1.10.0) (2026-08-27)


### Features

* **falkordb:** Add FalkorDB source and tools ([#3692](googleapis/mcp-toolbox#3692)) ([a94702c](googleapis/mcp-toolbox@a94702c))
* **mcp:** Add Secure Parameters support as Toolbox experimental extension ([#3394](googleapis/mcp-toolbox#3394)) ([9750d2d](googleapis/mcp-toolbox@9750d2d))
* **server/mcp:** Support com.google.cloud/toolbox.v1 extension in v20260728 ([#3801](googleapis/mcp-toolbox#3801)) ([f4f7da6](googleapis/mcp-toolbox@f4f7da6))
* **skill:** Add fix-failing-tests skill for mcp-toolbox ([#3821](googleapis/mcp-toolbox#3821)) ([168e69c](googleapis/mcp-toolbox@168e69c))
* **sources:** Support native read-only mode and dynamic tool annotations ([#3872](googleapis/mcp-toolbox#3872)) ([c257022](googleapis/mcp-toolbox@c257022)), refs [#3615](googleapis/mcp-toolbox#3615) [#3816](googleapis/mcp-toolbox#3816) [#3618](googleapis/mcp-toolbox#3618) [#3851](googleapis/mcp-toolbox#3851) [#3619](googleapis/mcp-toolbox#3619) [#3617](googleapis/mcp-toolbox#3617)
* **tools/firestore-mongodb:** Add tools for execute mql and get schema ([#3826](googleapis/mcp-toolbox#3826)) ([4a85d75](googleapis/mcp-toolbox@4a85d75))
* **tool/mongodb:** Allow collection to be specified at runtime ([#3715](googleapis/mcp-toolbox#3715)) ([7626eaf](googleapis/mcp-toolbox@7626eaf))


### Bug Fixes

* **cloud-storage:** Resolve symlinks when enforcing local path boundaries ([#3810](googleapis/mcp-toolbox#3810)) ([c2ada64](googleapis/mcp-toolbox@c2ada64))
* **config:** Compare env var offsets in rune space when skipping comments ([#3856](googleapis/mcp-toolbox#3856)) ([2e76934](googleapis/mcp-toolbox@2e76934))
* Merge prebuilt tools when reloading custom config ([#3864](googleapis/mcp-toolbox#3864)) ([5a6d865](googleapis/mcp-toolbox@5a6d865))
* Normalize postgres UUIDs to strings ([#3806](googleapis/mcp-toolbox#3806)) ([3b02f1d](googleapis/mcp-toolbox@3b02f1d))
* **postgres:** Filter background processes in postgres-list-active-queries ([#3885](googleapis/mcp-toolbox#3885)) ([3d9e62a](googleapis/mcp-toolbox@3d9e62a))

| **OS/Architecture**                                                                                       | **Description**                                                                                                          | **SHA256 Hash**                                                     |
| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------- |
| [linux/amd64](https://storage.googleapis.com/mcp-toolbox-for-databases/v1.10.0/linux/amd64/toolbox) ([Signature](https://storage.googleapis.com/mcp-toolbox-for-databases/v1.10.0/linux/amd64/toolbox.asc)) | For **Linux** systems running on **Intel/AMD 64-bit processors**.                                                        | 7e15dba09e6f957f64ce5924a0aa06b12cdf83ab26119813b0fa40edab566dd4    |
| [darwin/arm64](https://storage.googleapis.com/mcp-toolbox-for-databases/v1.10.0/darwin/arm64/toolbox)     | For **macOS** systems running on **Apple Silicon** (M1, M2, M3, etc.) processors.                                        | c994f06781462abba4171cb4844776c45605e391c57dc96adb3e130c81b53825    |
| [darwin/amd64](https://storage.googleapis.com/mcp-toolbox-for-databases/v1.10.0/darwin/amd64/toolbox)     | For **macOS** systems running on **Intel processors**.                                                                   | 12ebf78d9d05e8f3fe90c5d02ae14f2ccd96cf036f3dfba430bc32e3cfeadfd4    |
| [windows/amd64](https://storage.googleapis.com/mcp-toolbox-for-databases/v1.10.0/windows/amd64/toolbox.exe) | For **Windows** systems running on **Intel/AMD 64-bit processors**.                                                      | 734783941cb5864c0e5d4d78be625f8b12be23b01d94781d7fa7db9b3c25aac6    |
| [windows/arm64](https://storage.googleapis.com/mcp-toolbox-for-databases/v1.10.0/windows/arm64/toolbox.exe) | For **Windows** systems running on **ARM 64-bit processors**.                                                            | d9be7c2ce1d2e29c20f2974cbac4cde857adad836cee565d2584f3fbcc97f096    |</pre>
  <p>View the full release notes at <a href="https://github.com/googleapis/mcp-toolbox/releases/tag/v1.10.0">https://github.com/googleapis/mcp-toolbox/releases/tag/v1.10.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!17982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release candidate Use label to signal PR should be included in the next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Env var substitution silently skipped when config contains non-ASCII comments

2 participants