Skip to content

update-shape.py: _is_block_header cuts with str.strip(), so a line with U+00A0 or U+3000 in front of shape: or files: is taken as the block header, where the reader strips only a space and a tab and reads it as another key #1220

Closed

Description

@brettheap

Goal: _is_block_header reads a line's blanks as the YAML reader does, a space or a tab and nothing else, so a line with U+00A0 or U+3000 in front of shape: or files: is no header to the rewrite, as it is none to the reader, and the header count refuses it by name.

Filed by lane openRepoShape-3, from RV1188's independent review of #1188 (#1176) at 024084b9 (#1188 issuecomment-6360127603), its Observation ("nothing for this PR ... a follow-up issue is the lane's call"). It did not hold the landing: the review was READY, and #1188 is merged (423e66760, in main ef619c74; it changed tests/test_bom_tool_io.py alone). Line numbers are main's at ef619c74; RV1188's :1695-1698 are :1697 and :1700 here. The defect is on main now.

The header finder strips what the reader does not

State. _is_block_header (update-shape.py:1678) returns False for a line that starts with a space or whose indentation holds a tab, if line.startswith(" ") or "\t" in line[:len(line) - len(line.lstrip())] (:1697), and otherwise returns _split_key(_strip_comment(line.strip())) == (key, "") (:1700). str.lstrip() and str.strip() with no argument cut every Unicode space, U+00A0 and U+3000 among them (checked with the standard library, not the tool: with no argument they remove both, and stripping the reader's two characters leaves both). The docstring says (:1693-1694) that the text is ".strip()ped first, as _tokenise strips it". It is not. The reader's _significant_text strips _YAML_WHITE (scripts/repo_shape.py:859-870), which is a space and a tab (:271), and _tokenise (:1133) measures indentation as len(raw) - len(raw.lstrip(" ")). The callers are rewrite_shape_pin (update-shape.py:1786, the files header) and _shape_block_bounds (:1939, the shape header).

What happens. RV1188: "A direct call to _repin wrote such a manifest, while parse_yaml reads that line as another key." and it "was not run through apply end to end". Read from the reader's code, _split_key (repo_shape.py:377) takes the key as the text before the colon with only _YAML_WHITE stripped, so the key parse_yaml gets is U+00A0 followed by shape (or files), a key of its own, at column 0. To the reader there is no shape: header there, and the rewrite finds one and writes the new block under it. Whether check and apply reach the rewrite on such a file at all, or the reader refuses the file first, is not known; the writer measures that first. A header the reader does not see should end in the count's refusal (update-pin-unrecognised or update-manifest-no-shape).

Direction. Strip with the reader's own blanks in _is_block_header: line.strip(_YAML_WHITE) and line.lstrip(_YAML_WHITE). update-shape.py already imports _split_key and _strip_comment from repo_shape (:180), so _YAML_WHITE is one more name from the same place. Correct the docstring sentence. A line the reader does not read as the key is then no header, as the file's indented and quoted-key-then-text cases already are, and the count refuses it in its own words. No command and no flag.

  • The same family: rewrite_manifest's line.strip() before startswith("commit:") (:1853) and _shape_block_bounds' end test line.strip() and not line.startswith((" ", "\t")) (:1961) use the same bare strip. They are not asked here. The writer reads each against the reader, and the PR says which were left and why.

  • The pin rows go in tests/test_update_shape_apply_lines_and_headers.py: test_a_line_that_is_no_files_header_to_the_reader_is_still_counted_none (:218, its headers parametrized at :212-217) takes one row with U+00A0 in front of files: and one with U+3000, expecting update-pin-unrecognised and "has 0 files line(s)". The manifest rows go in tests/test_update_shape_header_comments.py: test_a_manifest_with_no_shape_header_still_names_this_kinds_validator (:212), whose damage rows (absent, indented, commented-out) take the same two, expecting update-manifest-no-shape.

  • A pin whose files: line has U+00A0 in front: rewrite_shape_pin refuses update-pin-unrecognised with "0 files line(s)". The same for U+3000. Each row fails before and passes after.

  • A manifest whose shape: line has U+00A0 in front: rewrite_manifest refuses update-manifest-no-shape, naming the kind's validator. The same for U+3000.

  • End to end, check and apply over such a manifest or pin do what the reader does, a refusal by name with the tree untouched; the writer measures that and pins it.

  • A header with a comment, a quoted key, and an ASCII-space-indented line keep their answers: the two files' other rows pass unchanged.

  • One mutant, the bare strip() back, fails the new rows; each mutant run is restored and checked with cmp.

Related: #1188, #1176 (the issue #1188 is for: the byte-order-mark rows of the two tools), #674 (the key read the reader's way, which the docstring cites), and #458 (the tracker for update-shape.py and bump-leg.py, keeping a project's shape copies and leg pins current).

Size: S.

Lane: openreposhape-3 (openRepoShape-3)

Activity

  1. added this to the v1.2.1 milestone on Oct 23, 2026
  2. brettheap commented on Oct 23, 2026

    @brettheap
    ContributorAuthor

    CLAIMED — lane openRepoShape-3, session b30e8b49-f249-4668-adb1-1dbfa93c09e1@Eagle, 2026-10-23T18:41:10Z, for #1220

    Logged in lanes/log/openRepoShape-3.md at 1596ab23ad62fed49a4e2a8f90adc25f2b39a36e.

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

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions