Skip to content

scripts/repo_shape.py _split_flow ignores a backslash inside a double-quoted flow item, so pins: ["x\",y"] reads back as two items x\ and y" where the same text as a block sequence item reads as the one item x",y #213

Closed

Description

@brettheap

Lane: openreposhape-5 (openRepoShape-5)

Found by this lane while fixing #199, whose writer saw it and left it out of that fix. Pre-existing on main e4decfb. Latent: nothing this repository writes or ships can hold such an item today (see the last paragraph), so this is a reader that disagrees with itself, not a live failure.

What is wrong. The YAML subset reader's _split_flow (scripts/repo_shape.py:339-360) ends a quoted flow item at the next matching quote character and never looks at a backslash. So an escaped quote \" inside a double-quoted item ends the quote early, the comma after it splits the item, and a ] or , that was inside the quotes is read as structure. _split_key_flow (:322-336) has the same omission. _strip_comment (:200) and _split_key (:224) already skip the character after a backslash inside a double-quoted scalar, and _scalar / _unescape resolve \", so a double-quoted scalar is read one way everywhere except where it is a flow item.

SHAPE=<openRepoShape checkout>; TMP=$(mktemp -d)
printf 'pins: ["x\\",y"]\n'   > "$TMP/flow.yaml"
printf 'pins:\n  - "x\\",y"\n' > "$TMP/block.yaml"
SHAPE=$SHAPE TMP=$TMP python3 - <<'PY'
import os, sys
sys.path.insert(0, os.environ["SHAPE"] + "/scripts")
from pathlib import Path
from repo_shape import load_yaml, parse_yaml, YamlError
tmp = Path(os.environ["TMP"])
print("flow  :", load_yaml(tmp / "flow.yaml"))
print("block :", load_yaml(tmp / "block.yaml"))
for text in ('pins: ["a\\"]", "b"]', 'pins: [["x\\",y"], z]', 'pins: {k: "x\\",y", j: 2}', 'pins: {"a\\": b": 1}'):
    try:
        print(f"{text!r:36} ->", parse_yaml(text))
    except YamlError as exc:
        print(f"{text!r:36} -> YamlError: {exc}")
PY

Observed on main e4decfb:

flow  : {'pins': ['x\\', 'y"']}
block : {'pins': ['x",y']}
'pins: ["a\\"]", "b"]'               -> {'pins': ['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: 'y", j: 2'
'pins: {"a\\": b": 1}'               -> {'pins': {'a\\': 'b": 1'}}

Row 1 is the report: one item x",y reads as two, x\ and y", and nothing refuses it. Row 3 is worse: two items a"] and b read as one garbled item, because the quote state is inverted from the escaped quote on, so the comma between the two items falls inside a "quote" and is not split. Rows 4 and 5 are refusals of a valid document, and row 6 is a wrong key and value from _split_key_flow. The reader's own header says it "raises rather than guessing", because a validator that silently mis-reads its own contract file is worse than one that will not start.

Expected. The same text reads the same in a flow and in a block: pins: ["x\",y"] is ['x",y'], ["a\"]", "b"] is ['a"]', 'b'], and {"a\": b": 1} is {'a": b': 1}. Inside a double-quoted item, _split_flow and _split_key_flow skip the character after a backslash, as _strip_comment and _split_key do. A single-quoted item has no backslash escape and keeps its toggle. A test pins these cases.

Reach. The four writers of a flow sequence write bare words: adopt-project.py:868 (pins, each checked by PIN_NAME_RE, [A-Za-z0-9_.-] and one /), :894-896 (allow_empty_legs, choices=EXTRACTED_LEGS), scripts/shape_materialize.py:986 (also_matches) and :1006-1007 (referent_chain). None quotes an item, and none of the 14 tracked YAML files holds a flow item with a double quote in it. So the defect shows only on a file a person edits or another tool writes: the adoption plan is "meant to be edited", and json.dumps of a list is valid flow YAML with exactly this escape. A writer added later that put y()'s output in a flow would meet it.

Not claimed.

Activity

  1. brettheap commented on Oct 11, 2026

    @brettheap
    ContributorAuthor

    CLAIMED — lane openRepoShape-5, session aed6225f-5615-4442-8a05-1652232a24d9@Eagle, 2026-10-11T17:14:52Z, for #213

    Logged in lanes/log/openRepoShape-5.md at a8a82ba38c8fc6ea0ec4ca771e4426a75022cb4d.

    The three reads (lane-collision-protocol Rule 1):

    1. existing `CLAIMED —` comments on opensoft/openRepoShape#213:
       none
    2. `gh pr list --repo opensoft/openRepoShape --state all --search "#213"`, kept where the row or its body names `#213`:
       none
    3. `git ls-remote --heads [email protected]:opensoft/openRepoShape` branches naming `213` as a whole token:
       none
    
  2. added a commit that references this issue on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions