Repository navigation
repo_shape.py: _split_flow and _split_key_flow take the character after a backslash inside a double-quoted flow item, so pins: ["x\",y"] reads as the one item x",y its block twin reads, not as x\ and y" (#213) - #244
Conversation
… after a backslash inside a double-quoted flow item, so `pins: ["x\",y"]` reads as the one item `x",y` its block twin reads, not as `x\` and `y"` (#213) The YAML subset reader's two flow scanners ended a double-quoted item at the next `"` and never looked at a backslash, so an escaped quote ended the item early and the `,` or `]` after it was read as structure. `_strip_comment` and `_split_key` already take the character after a backslash inside double quotes, and `_scalar` resolves `\"`, so the same scalar read one way in a block and another in a flow. On main 20e13f0: `["x\",y"]` read as `x\`, `y"`; `["a\"]", "b"]` as the one item `a"]", "b`; `[["x\",y"], z]` and `{k: "x\",y", j: 2}` were refused; and `{"a\": b": 1}` read as the key `a\`. `_split_flow` now appends the character after a backslash inside a double-quoted item and moves past it. `_split_key_flow` now returns `_split_key(text)`: since v0 (86bf553) it was `_split_key` written again as a for loop with the skip left out, and nothing else in the two bodies differs, so one scanner cannot drift from the other again. A single-quoted item has no backslash escape; its `''` is still read by toggling twice, unchanged. Evidence: old and new agree (results and exceptions) on all 229,624 of 266,430 generated inputs whose double-quoted spans hold no backslash, and the new `_split_key_flow` equals the old `_split_key` on all of them. 50,000 `json.dumps` strings read back unchanged as a flow item, a block item, a flow-mapping key and value, and nested: 0 mismatches, against 16,132 on main. tests/test_yaml_flow_quotes.py pins the issue's five rows and the flow/block twin (all six fail on main), plus an escaped backslash before the closing quote and a single-quoted sequence and mapping, which pass on main and pin what must not change: each fails under a mutant (a look-back fix; `_split_key_flow` left unfixed; the skip applied in single quotes too). Left out: no new escape, no new refusal, and the reader's header still says "single-level" flow collections although `_flow_value` nests. Lane: openreposhape-5 (openRepoShape-5) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-quoted flow item's text reads as plain text or is refused, never a StopIteration, and the module docstring names the one writer that can quote a flow item Review nit N1 on 8c656f4: no test pinned the `""` default of `next(chars, "")` in `_split_flow`. With `next(chars)` all nine tests passed, and `parse_yaml('k: ["a\\]')` died with a bare StopIteration out of the scanner, so `load_yaml` would print a traceback instead of a REFUSED line. tests/test_yaml_flow_quotes.py, eight new tests: - four texts whose double-quoted item ends in a backslash right before the closing bracket or brace (`k: ["a\]`, `k: ["\]`, `k: {a: "x\}`, `k: [["\]]`). On this head each reads as plain text, `"a\` and so on, and each equals its block twin, which the test also reads. Not valid YAML (PyYAML refuses all four), so they pin that the reader does not crash. - a mapping key ending in the backslash before the closing brace (`k: {"a\}`): a YamlError, `flow mapping entry without a key`. - the same backslash at the very end of the text, for a sequence and a mapping: a YamlError, `not a flow collection`. `_flow` refuses these before `_split_flow` runs, so they do not guard the default; they pin the other half of "at the end". - one read through `load_yaml` from a file written as bytes: `Refusal` `yaml-unparsable`, the file named. Under the mutant `next(chars)`, six of the eight fail with StopIteration (the four before the closer, the key, the file); the two at the very end of the text pass, as above. On the head, 17 passed here and 11 in test_load_yaml_refusals. The nine tests of 8c656f4 pass under the mutant, as the review found. Also corrects the module docstring, which said nothing this repository writes puts a quote in a flow item: the `referent_chain` writer in `shape_materialize.py` writes the operator's chain links as given (N4). scripts/repo_shape.py is not touched. Lane: openreposhape-5 (openRepoShape-5) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 1 day and 3 hours by commenting |
Reviewer's GuideFix flow parsing so escaped quotes and backslashes in double-quoted items do not prematurely terminate scanners or expose following commas, brackets, or colons as structure. The change unifies flow-mapping key parsing with the existing escape-aware scanner and adds regression tests covering valid flow/block parity and safe handling of malformed dangling escapes. Sequence diagram for flow-mapping key parsingsequenceDiagram
participant Flow as _flow
participant KeyFlow as _split_key_flow
participant Key as _split_key
participant Scanner as Escape-aware scanner
Flow->>KeyFlow: _split_key_flow(entry)
KeyFlow->>Key: _split_key(entry)
Key->>Scanner: scan quotes, escapes, and top-level colon
Scanner-->>Key: key/value boundary
Key-->>KeyFlow: unquoted key and value
KeyFlow-->>Flow: mapping entry
Flow diagram for escape-aware YAML collection scanningflowchart LR
Input["YAML flow collection text"] --> Scanner["_split_flow"]
Scanner --> Quote{double-quoted item?}
Quote -->|yes| Escape{backslash?}
Escape -->|yes| Consume["consume next character"]
Escape -->|no| Structure["recognize quote and top-level structure"]
Consume --> Scanner
Structure --> Result["split only at top-level commas"]
Quote -->|no| Structure
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
(lane openRepoShape-5, 2026-10-11T20:07Z) @codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
…fix/plan-report-stdout-encoding (#214) One conflict, scripts/shape_materialize.py, the single add/add hunk right after write_lf: #199's write_paths_listing (from main) and this branch's escape_what_stdout_cannot_encode with SURROGATEESCAPE_THEN_BACKSLASHREPLACE, _registered_surrogateescape_then_backslashreplace, _surrogateescape_then_backslashreplace and _is_escaped_byte. Resolved by keeping both sides whole, this branch's block first and write_paths_listing after it, two blank lines between. Every other file merged without a conflict and is taken as main has it. No code was written for the merge. Lane: openreposhape-5 (openRepoShape-5) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ng-paths main moved to 4835fb4: #224 (e7d1720, update-shape.py), #244 (404760f, repo_shape.py `_split_flow`) and #247 (4835fb4, the plan writer escapes every character that is not printable). The textual merge is clean. The next commit takes #247's one assertion that this branch's spelling changes. Lane: openreposhape-3 (openRepoShape-3) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…, #213 and #199 land beside #190, and the `repo_shape` import list carries #199's `double_quoted` with #190's `redacted`, `remote_is_a_path`, `remote_key` and `remote_local_path` Main moved from 54aa69a to 4835fb4: e7d1720 (#208 via #224), 404760f (#213 via #244) and 4835fb4 (#199 via #247). One conflict hunk, in adopt-project.py, and it takes BOTH sides: 1. The `repo_shape` import list. #199 adds `double_quoted`, which `y` now spells every quoted plan scalar with; #190 adds `redacted`, `remote_is_a_path`, `remote_key` and `remote_local_path`, which its relative-url check calls (`_Resolution.same_as` and `__str__`, `_default_remote`, `_relative_url_findings`). Main's line is kept as main wrote it, and #190's four names follow `parse_yaml` in the list's order. Either side's list alone leaves a name the merged code calls undefined. Merged with no conflict: - adopt-project.py, #199's other hunks: `_PLAIN_RE` ending at `\Z`, `y` through `double_quoted`, `_spelled`'s docstring, `_shown` and the four report lines that print through it, and `write_paths_listing` in the `shape_materialize` import and in `_extract_leg`. None touches a #190 line. #190's findings and NOTE already print every path and url through `_spelled`, which is what `_shown` falls back to for a name that is not printable. - scripts/repo_shape.py: #199's escape table (`DOUBLE_QUOTED_ESCAPES` with `\r`, `CODE_POINT_ESCAPES`, `double_quoted`, `_escaped`, `_escape_at`, the one-pass `_unescape`), with its module-docstring line and its `_BLOCK_SENTINEL` comment, and #213's `_split_key_flow` and `_split_flow`, are all in the YAML reader at the top of the file. #190's `REMOTE_PORT_RE`, `REMOTE_HOST_ALIASES` and `remote_key` are in the remote helpers some 1,400 lines below, and call nothing main changed. Each side's added and removed lines are the same before and after the merge, byte for byte. - update-shape.py (#208), scripts/shape_materialize.py (#199) and main's three test files are main's blobs; #190's three test files are this branch's. #190's added and removed lines against 4835fb4 are its lines against 54aa69a, but for the import hunk. Lane: openreposhape-1 (openRepoShape-1) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…) into fix/adopt-record-submodule-placement Brings in e7d1720 (#208), 404760f (#213) and 4835fb4 (#199) on top of 54aa69a. No rebase. #199 landed first, so this branch is the one that lands second, and it takes #199's side of the double-quoted escape section, as cd2a622's message and lane openRepoShape-2's review of e167d8b both said it would. Conflicts, and how each was resolved: - scripts/repo_shape.py, two hunks (textual): the escape section and `_unescape`'s docstring. Both sides added `CODE_POINT_ESCAPES`, `_HEX_DIGITS` and an `_escape_at` whose body is the same line for line, and both reworded the docstring; #199 also added `r` to `DOUBLE_QUOTED_ESCAPES` and the writer, `double_quoted` with `_escaped` and `_ESCAPE_OF`. The auto-merge had also left this branch's own copies of `CODE_POINT_ESCAPES`, `_HEX_DIGITS` and `_escape_at` beside main's. Resolved as main's file, byte for byte, plus this branch's one change to it that is not about escapes: 379763c's `path_spelling_fault` section and its line in the module docstring, applied with `git apply`. `git diff origin/main -- scripts/repo_shape.py` is that 51-line addition alone. Merged without a conflict, and checked: - adopt-project.py: main's `y` now quotes with `double_quoted`, and this branch's `submodule_record` still quotes with `_quoted`, which reads main's table now, so it writes a carriage return as `\r`, where it wrote `\x0d`. The two writers give the same text for every character to U+2FFF, every surrogate and seven more (14,343 compared, 0 different). The next commit removes `_quoted`. - scripts/shape_materialize.py: main's `write_paths_listing` and this branch's `path_spelling_fault` import and `LEG_SEGMENT_REASONS`. Every merged module compiles. On this merge, tests/test_windows_paths.py, test_adopt_plan_escapes.py, test_yaml_flow_quotes.py, test_manifest_validator.py and the record's two name tests in test_adopt_submodules.py: 218 passed. Lane: openreposhape-1 (openRepoShape-1) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-notice It merged with no conflict. Main brings six commits since 54aa69a: - e7d1720, update-shape.py (#208 via #224); - 404760f, scripts/repo_shape.py's double-quoted flow items (#213 via #244), with tests/test_yaml_flow_quotes.py; - 4835fb4, adopt-project.py's plan writer escapes (#199 via #247), with tests/test_adopt_plan_escapes.py; - b538015, scaffold-project.py's leg paths against the shape's own paths (#197 via #234); - 150c41d, update-shape.py's `apply --add` (#202 via #233); - 39ac59c, scaffold-project.py's leg mount `--force` (#229 via #235). Two of them touch adopt-project.py, and no hunk of either meets this branch's: - 4835fb4 changes the plan writer (`y`, `_PLAIN_RE`), adds `_shown` to the plan and check reports, and writes the `--paths-from-file` listing in `_extract_leg` through `write_paths_listing`. This branch changes other lines of `_extract_leg`: it reads the tree digest before the push and pushes through `_push_the_leg`. The signature is the same on both sides, so main's new direct `_extract_leg` test calls it as written. - b538015 moves `_overlap`, `_first_and_more`, `MOVE_THE_LEG` and `CASE_ASIDE` into scripts/shape_materialize.py, and imports the first three back under the same names. This branch adds no use of any of them. A `symtable` check finds no name that the merged adopt-project.py, scaffold-project.py or scripts/shape_materialize.py reads and nothing binds. `git diff -U0` of this merge against 39ac59c equals the branch's against 54aa69a, apart from the hunk headers. On the merged tree, tests/test_adopt_plan_escapes.py, tests/test_yaml_flow_quotes.py, tests/test_scaffold_leg_path_collisions.py and tests/test_adopt_leg_path_collisions.py give 275 passed. Lane: openreposhape-1 (openRepoShape-1) Co-Authored-By: Claude Opus 5.5 <[email protected]>



Lane: openreposhape-5 (openRepoShape-5)
Claim: #213 (comment)
What
scripts/repo_shape.pyhas two scanners for a flow collection,_split_flow(splits[a, b]and{k: v, ...}at top-level commas) and_split_key_flow(splits one flow-mapping entry at its key's:). Neither skipped the character after a backslash inside a double-quoted item, as_strip_commentand_split_keyalready do. So\"ended the item at the escaped quote, and the,or]after it read as structure._split_flownow takes the character after a backslash while inside a DOUBLE-quoted item (scripts/repo_shape.py, the loop at_split_flow)._split_key_flowis nowreturn _split_key(text). Since v0 (86bf553) it was_split_keyre-spelled as aforloop with the backslash skip left out; nothing else differed._split_keyalready returns at the first top-level:, so a value that opens a flow is still fine, and already returns None at a[or{before the colon, as the old loop did.tests/test_yaml_flow_quotes.py(new): the issue's table, the block-sequence twin, the escaped-backslash guard, two single-quoted controls, and (fix round 1) eight cases for a backslash that is the last character of a double-quoted flow item, which pin that the reader refuses or reads it as plain text and never dies with aStopIteration.A single-quoted item has no backslash escape and keeps its toggle (
''is its only escape). No new refusal in the code, no new escape table, nothing else in the reader changes.On INVALID YAML the reads move, and not always the way they were. A double-quoted flow item that never closes now reads as plain text, the same as its block twin (
k: ["a\", b]is['"a\\", b']in a flow and in a block; PyYAML refuses it). Over a raw corpus of 654,312 documents, 607,073 of which PyYAML refuses, 264 of those read differently: 12 that main refused are now read, 7 that main read are now refused by the existing refusals, 95 swap one wrong read for another, and 150 change only the refusal text. All are invalid YAML. The root cause is_scalar(scripts/repo_shape.py:284), which treats any text that starts and ends with"as quoted and which predates this change:- "a\"readsa\in a block on main too. It is left for a follow-up issue.Why
The same text read differently in a flow collection and in a block sequence, and a valid document could be refused. Of the four writers here that emit a non-empty flow list, three write only values a regex or a choice list admits (
pins,allow_empty_legs,also_matches), and the fourth,referent_chain(scripts/shape_materialize.py:1010-1011), writes the operator-given chain links verbatim, unchecked (a GitHub repository name holds neither a quote nor a backslash, so a real chain does not reach it). Nothing else this repository writes can put a quote or a backslash into a flow item. A person editing the adoption plan, orjson.dumpsof a list, does. Reads on main, from the issue:pins: ["x\",y"]['x\\', 'y"'](one item read as two)['x",y'], equal to the block twinpins: ["a\"]", "b"]['a"]", "b'](two items read as one)['a"]', 'b']pins: [["x\",y"], z]YamlError: not a flow collection[['x",y'], 'z']pins: {k: "x\",y", j: 2}YamlError: flow mapping entry without a key{'k': 'x",y', 'j': 2}pins: {"a\": b": 1}{'a\\': 'b": 1'}{'a": b': 1}Evidence
_split_key_flowas on main fails only the mapping-key row. Applying the skip in single quotes too fails[sequence]when put in_split_flowalone,[mapping]when put in_split_keyalone, and both when put in both. Dropping the""default (next(chars)) fails 6 of the 8 dangling-backslash cases withStopIteration(the two at the very end of the text are refused by_flowbefore any scanner runs, so they do not reach it); the nine tests of the first commit all pass under that mutant, which is why the cases were added._split_key_flowleft unfixed fails only the mapping-key row (one of the five that fail on main), and the single-quote skip fails[sequence]or[mapping]depending on which scanner it is put in. The Mutations line above states it correctly._split_flow,_split_key_flow,_flow("[...]")and_flow("{...}")are identical, exceptions included. The new_split_key_flowequals the old_split_keyon all 266,430.json.dumpsstrings overab"\,[]{}:# 'as a flow item, a block item, a flow-mapping key and value, and nested: 0 mismatches here, 16,132 on main.",\",],,), each with its expected value: 0 wrong in the flow read, 0 in the block twin, 0 where they differ, 0 where PyYAML disagrees with the generator; main reads 42,141 of them wrong.Icon\rfile), socheckrefuses the whole plan asyaml-unparsablewith no entry to edit #199 (the adversarial review's own, independent run). The d5fdc22 merge is clean, and adopt-project.py plan writes a plan its own loader cannot parse when a source name holds a line break (the macOSIcon\rfile), socheckrefuses the whole plan asyaml-unparsablewith no entry to edit #199'sdouble_quotedover 40,000 strings (quotes, backslashes,,[]{}:#',\n \r \t, NUL, U+0085, U+2028, lone surrogates,é, an emoji, the literal textsx41,\x41,\") through flow sequence, flow-mapping key and value, nested flow, block sequence and block mapping has 0 mismatches there, against 27,210 on d5fdc22 alone.tests/test_yaml_flow_quotes.py): test_yaml_flow_quotes 17 passed (9 + 8); test_load_yaml_refusals 11; test_repo_hygiene 50. On 8c656f4, not re-run on 86ffe66: test_manifest_validator 39; test_pin_validator 19; test_cli_reference 13; test_adopt_plan 56 passed and 1 skipped (SHAPE_MEDXEHR_CLONEunset); test_shape_doctor 181 (the review re-ran these at 8c656f4 with the same counts,test_cli_referenceexcepted).Icon\rfile), socheckrefuses the whole plan asyaml-unparsablewith no entry to edit #199 (fix/adopt-plan-linebreak-names, which also editsscripts/repo_shape.py). Trial merges with its heads d566e12 and d5fdc22 are both clean. In the d5fdc22 merge: test_yaml_flow_quotes 9 passed, test_adopt_plan_escapes 59 passed, and adopt-project.py plan writes a plan its own loader cannot parse when a source name holds a line break (the macOSIcon\rfile), socheckrefuses the whole plan asyaml-unparsablewith no entry to edit #199'sdouble_quotedwriter round-trips 30,000 strings (quotes, backslashes,,[]{}:#,\r\n\t, NUL, U+0085, U+2028, a lone surrogate) through flow item, block item and flow-mapping key and value with 0 mismatches (5,767 on adopt-project.py plan writes a plan its own loader cannot parse when a source name holds a line break (the macOSIcon\rfile), socheckrefuses the whole plan asyaml-unparsablewith no entry to edit #199 alone, which is why the two belong together).git merge-tree --write-treeis clean.git diff --checkis clean; no added line holds a host path; the only new imports are in the test file and are the ones its siblings use.Left out
k: [it's, a]reads["it's, a"]while its block twin reads["it's", "a"], andk: [a"b, c]is misread the same way. That is a misread this change did not cause and does not fix; it needs its own change and its own differential check. It is NOT unchanged for every input in that class.k: [a"b\", c]read correctly on main, by accident: the\"closed the quote that the"in the middle of the item had opened, so main read['a"b\\"', 'c'], equal to its block twin and to PyYAML. It now reads['a"b\\", c'], one item, because the\"is taken as an escape inside the quote the middle"opened. In the adversarial review's raw corpus (47,239 valid documents) 5 regress, all of them in this class, and 6 are fixed; in a corpus built dense in this class (50,000 valid documents) 88 are right on main and wrong now, 4,574 are wrong on main and right now, and 19,934 are wrong on both. The follow-up fixes both directions, and nothing this repository writes puts a quote in the middle of a plain flow item (areferent_chainlink would have to be typed that way, which a repository name cannot hold)._scalarcheck behind them. Left for a follow-up issue.docs/cli.mdis untouched; no CLI surface changed.Closes #213
🤖 Generated with Claude Code
Summary by Sourcery
Fix YAML flow parsing so escaped quotes and backslashes are handled consistently across sequences and mappings.
Bug Fixes:
Enhancements:
Tests: