Skip to content

scripts/repo_shape.py _scalar takes any text that starts and ends with a quote for a quoted scalar and anything else for plain text, so an unterminated "abc reads as "abc, - "a\" reads as a\, and "a" b "c" reads as a" b "c, where PyYAML refuses each #250

Closed

Description

@brettheap

Lane: openreposhape-5 (openRepoShape-5)

Found by this lane's adversarial review of #213's fix (F1 and N5), where PR #244's body leaves it out for a follow-up issue. Pre-existing on main 54aa69a. Latent: every writer in this repository closes the quote it opens, so this is a reader that guesses where its header says it "raises rather than guessing", not a live failure.

What is wrong. _scalar (scripts/repo_shape.py:278) decides a scalar is quoted by looking only at its first and last characters: text[0] == '"' and text[-1] == '"' (:285) or the same with ' (:283). It never asks whether the last quote CLOSES the scalar that the first one opened. So an unterminated double-quoted scalar is not recognised as quoted at all and is read as the plain text, quote and all, or, when its last character happens to be an escaped ", it is read as quoted and the backslash survives. And a quoted scalar followed by more text is read as one scalar when the text ends in a quote. PyYAML 6.0.3 refuses every row below, and so should the reader.

SHAPE=<openRepoShape checkout>
SHAPE=$SHAPE python3 - <<'PY'
import os, sys
sys.path.insert(0, os.environ["SHAPE"] + "/scripts")
from repo_shape import parse_yaml, YamlError
def read(text):
    try:
        return repr(parse_yaml(text))
    except YamlError as exc:
        return f"YamlError: {exc}"
# every one of these is invalid YAML: PyYAML 6.0.3 refuses it
for text in ('created_by: "Brett Heap\n',     # the closing quote is missing
             'k: "abc\n',
             'k:\n  - "a\\"\n',                 # the only quote that could close it is escaped
             'k: "a\\", b\n',
             'k: "a" b "c"\n',                  # text after the closing quote
             'k: "a"b\n',
             "k: 'abc\n",
             "k: 'a' b 'c'\n",
             'k: ["a\\", b]\n',                 # the same, in a flow sequence
             'k: ["a, b]\n'):
    print(f"{text!r:30} ->", read(text))
PY

Observed on main 54aa69a:

'created_by: "Brett Heap\n'    -> {'created_by': '"Brett Heap'}
'k: "abc\n'                    -> {'k': '"abc'}
'k:\n  - "a\\"\n'              -> {'k': ['a\\']}
'k: "a\\", b\n'                -> {'k': '"a\\", b'}
'k: "a" b "c"\n'               -> {'k': 'a" b "c'}
'k: "a"b\n'                    -> {'k': '"a"b'}
"k: 'abc\n"                    -> {'k': "'abc"}
"k: 'a' b 'c'\n"               -> {'k': "a' b 'c"}
'k: ["a\\", b]\n'              -> {'k': ['a\\', 'b']}
'k: ["a, b]\n'                 -> {'k': ['"a, b']}

On fix/yaml-flow-escaped-quote 86ffe66 (PR #244) every row is the same except the flow row k: ["a\", b], which now reads ['"a\\", b'], the way its block twin k:\n - "a\", b reads: #244 makes the flow and block reads agree, and they agree on the wrong answer.

Row 1 is the one a person meets: a missing closing quote on a hand-edited created_by, reference or plan path is not refused; the value carries a leading " into every validator that reads it. Row 3 reads a\, a value with a backslash that no YAML reader would produce. Rows 5 and 6 read as one scalar, or as plain text, where YAML ends the scalar at the closing quote and refuses what follows.

Expected. A scalar that begins with a quote is ONE complete quoted scalar or the reader raises YamlError by name: no closing quote (a " closes only when no backslash escapes it; a ' closes at a ' not doubled), or text after the closing quote other than a comment, is a refusal, in a block, a flow item and a key alike. The reader's header already promises this ("raising rather than guessing"). The fix needs its own differential check: the 14 tracked YAML files read as before, the plan round-trip tests, and the review's flow-against-block fuzz.

Reach. Writers cannot emit it: y() (adopt-project.py:223) closes every quote it opens, and the templates quote free text with a closing quote (templates/assembly-root/project.yaml:32,42,46). So it shows only on a file a person edits or another tool writes. The review of #244 put a number on the neighbourhood: of 607,073 raw documents PyYAML refuses, 264 read differently on #244 than on main, and 12 that main refused are now read silently (k: ["\",[] reads ['"\\",[']). All are invalid YAML.

Found by. handoffs/openRepoShape/attachments/lane-openRepoShape-5/review213-report.md in opensoft/brett-wip (F1 and N5; the PR body's "Left out" says "left for a follow-up issue"). Re-run on main 54aa69a and on 86ffe66 for this issue.

Not claimed.

🤖 Generated with Claude Code

Activity

  1. brettheap commented on Oct 11, 2026

    @brettheap
    ContributorAuthor

    CLAIMED — lane openRepoShape-5, session e62c2fd7-176d-429d-89fb-0653dd08ad5f@Eagle, 2026-10-11T21:45:07Z, for #250

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

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

    1. existing `CLAIMED —` comments on opensoft/openRepoShape#250:
       none
    2. `gh pr list --repo opensoft/openRepoShape --state all --search "#250"`, kept where the row or its body names `#250`:
       none
    3. `git ls-remote --heads [email protected]:opensoft/openRepoShape` branches naming `250` as a whole token:
       none
    
  2. added 7 commits that reference this issue on Oct 11, 2026
  3. added 6 commits that reference this issue on Oct 12, 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