Commit 2e76934
fix(config): compare env var offsets in rune space when skipping comments (#3856)
## 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
- [x] Make sure you reviewed
[CONTRIBUTING.md](https://github.com/googleapis/mcp-toolbox/blob/main/CONTRIBUTING.md)
- [x] Make sure to open an issue as a
[bug/issue](https://github.com/googleapis/mcp-toolbox/issues/new/choose)
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
- [x] Ensure you have manually reviewed the entire diff before
requesting a
review
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change
🛠️ Fixes #3855
Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com>1 parent 0fe2e30 commit 2e76934
2 files changed
Lines changed: 41 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
80 | 89 | | |
81 | | - | |
| 90 | + | |
82 | 91 | | |
83 | 92 | | |
84 | 93 | | |
| |||
141 | 150 | | |
142 | 151 | | |
143 | 152 | | |
144 | | - | |
145 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
146 | 157 | | |
147 | 158 | | |
148 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
149 | 163 | | |
150 | 164 | | |
151 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
142 | 165 | | |
143 | 166 | | |
144 | 167 | | |
| |||
0 commit comments