Repository navigation
Preserve quotes and version prefixes in YAML revisions - #68
tianhaogutum wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/sync_with_uv/sync_with_uv.py" line_range="117" />
<code_context>
- "yaml": re.compile(r"^\s*rev\s*:\s*(?P<repo_rev>\S*).*$"),
+ # Keep YAML quote delimiters outside the revision span, as for TOML.
+ "yaml": re.compile(
+ r"""^\s*rev\s*:\s*(?P<quote>['"]?)(?P<repo_rev>\S*?)"""
+ r"(?P=quote)(?=\s|$).*$"
+ ),
</code_context>
<issue_to_address>
**Quoted revisions become invalid YAML**
When a quoted YAML `rev` is updated using a custom version template whose result contains the matching quote character, the target revision is spliced between the existing delimiters without escaping, so a quote-bearing custom version template turns an otherwise valid quoted `rev` into invalid YAML and config validation fails.
Escape the replacement as a YAML scalar value for the captured quote style before splicing it into the line.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the new YAML match captures the wrong revision, the sync tool could write an incorrect rev into a user's config file; reverting the code would not undo that edit, but the affected config is bounded and can be corrected or regenerated.
Blocking findings: src/sync_with_uv/sync_with_uv.py:117
| "yaml": re.compile(r"^\s*rev\s*:\s*(?P<repo_rev>\S*).*$"), | ||
| # Keep YAML quote delimiters outside the revision span, as for TOML. | ||
| "yaml": re.compile( | ||
| r"""^\s*rev\s*:\s*(?P<quote>['"]?)(?P<repo_rev>\S*?)""" |
There was a problem hiding this comment.
🟡 Medium · Quoted revisions become invalid YAML
When a quoted YAML rev is updated using a custom version template whose result contains the matching quote character, the target revision is spliced between the existing delimiters without escaping, so a quote-bearing custom version template turns an otherwise valid quoted rev into invalid YAML and config validation fails.
Escape the replacement as a YAML scalar value for the captured quote style before splicing it into the line.
Prompt for AI agents
In `src/sync_with_uv/sync_with_uv.py` at line 117:
**Quoted revisions become invalid YAML**
When a quoted YAML `rev` is updated using a custom version template whose result contains the matching quote character, the target revision is spliced between the existing delimiters without escaping, so a quote-bearing custom version template turns an otherwise valid quoted `rev` into invalid YAML and config validation fails.
Escape the replacement as a YAML scalar value for the captured quote style before splicing it into the line.
Summary
The YAML
revregex inprocess_config_text()captured the surrounding quotes as part of the revision. As a result, a quotedrevthat already matcheduv.lockwas reported as changed (--checkexited 1) and rewritten without its quotes. For repos without a version template, it also lost the inferredvprefix ('v1.5.0'→1.5.0).This change makes the YAML regex keep optional, matching quote delimiters outside the
repo_revgroup, as the TOML regex already does. The existing version-template logic and in-place splice are unchanged, so the original quotes and any trailing comment are preserved.Reproduction
Starting from an empty directory with
uvinstalled:Expected:
Both revisions already match
uv.lock, so the file is left unchanged:0 packages would be changed, 2 packages would be left unchanged.and--checkexits 0.Actual:
--checkexits 1.Changes
src/sync_with_uv/sync_with_uv.py: YAMLrevregex only (one expression).tests/test_quoted_revs.py: 25 test cases covering single and double quotes; already-current and stale revisions; inferred, built-in and user version templates; trailing comments; LF, CRLF and no final newline; quoted numeric-looking revisions staying strings (checked withpre-commit validate-config); repeated write,--checkand--diffCLI runs; the unaffected TOML path; and unquoted refs that contain a quote character.CHANGELOG.md: entry under Unreleased → Bug Fixes.Testing
main(0d242e3) code: 21 failed, 4 passed. With this change: 25 passed.ruff check,black --check .,mypy,ty checkpass;prek run mdformatpasses onCHANGELOG.md.Out of scope: quoted
repo:URLs, multi-line or escaped YAML scalars, and general YAML parsing.