Skip to content

fix(#981): skip comments and quoted text when tracking heredocs in the URL-host guard - #984

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/981
Oct 8, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/981

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #981.

_check_url_in_comment's heredoc-open tracking ran _HEREDOC_OPEN against every line, including #-comment lines, so a comment merely mentioning <<WORD (e.g. 'was rewritten from cat <<EOF to printf') could leave the tracker open for the rest of the file and silently disable the URL-host-in-comment guard for every later line. The sibling _check_typed_heredoc already skipped comment lines for this reason; this guard's own tracking did not.

Fixed by skipping heredoc-open detection on comment lines. The issue's own follow-up comment also asked for two related fixes, both implemented here:

  • a <<WORD-shaped substring sitting inside an ordinary quoted string (not a real heredoc opener) must not open the tracker either -- added _in_quotes_before, a complete-quoted-span regex scan;
  • an opener that is never closed by EOF is now reported as an offense naming the opening line, instead of silently swallowing the rest of the file.

Self-review

Two reviewers ran after the first commit. One finding was fixed in a second commit: the original _in_quotes_before used a naive quote-TOGGLE (flip on any quote character, flip back on the next matching one), which misread a REAL heredoc opener as 'inside quotes' whenever an unmatched apostrophe from an ordinary English contraction (it's, don't) appeared earlier on the same line -- the opposite failure direction from the one #981 itself was filed to fix. Rewritten to match only complete quoted spans instead.

One adjacent finding was logged rather than fixed, below the filing bar. Anchor, verbatim from trap.d/981.heredoc-quote-scan-is-escape-blind.md: Logged to trap.d/981.heredoc-quote-scan-is-escape-blind.md rather than fixed, because real backslash-escape-aware shell quote parsing is materially more work than this issue needed. In full: the quote scan (both before and after the rewrite above) has no backslash-escape awareness, so an escaped quote inside a real quoted string before a real heredoc opener is misread. Confirmed this is a pre-existing limitation, not a regression from this pull request -- the same wrong answer comes out of both the old and new implementation. Ranked misreports/non-blocking per the release ranking table.

A second, lower-severity adjacent observation, also below the filing bar (declined, not ranked by the reviewer as needing its own finding). Anchor, verbatim: a line with two such shapes where the first is correctly recognized as quoted never looks for a second, real opener later on the same line. In full: _HEREDOC_OPEN.search() only finds the first heredoc-opener-shaped match per line, so a second real opener on a line after a correctly-recognized quoted one is never looked for. This lands in the safe direction -- the tracker simply never opens for it, nothing is silently swallowed -- and no shipped file currently has this shape, so it is not fixed here either; also noted in the trap.d fragment above.

Tests

Red confirmed against the pre-fix code (git stash the changed script, run the targeted tests, git stash pop): 3 failed, 10 passed. Green: 13 passed. Full home-file run: 89 passed. Narrowed run only, per this repo's CI-is-the-gate convention -- the full pytest suite was not run locally.

Docs

README.md never documented this internal CI guard's own regex-matching mechanism, so nothing there needed updating.

[AI-generated]

fdaviddpt and others added 2 commits October 8, 2026 04:13
…in the URL-host guard

`_check_url_in_comment`'s heredoc-open tracking (#919/#978) ran `_HEREDOC_OPEN`
against every line, including `#`-comment lines -- bash never opens a
heredoc from inside a comment, so a comment line that merely mentions
`<<WORD` could leave the tracker "open" for the rest of the file and
silently disable the URL-host-in-comment guard past that point. The
sibling `_check_typed_heredoc` already skipped comment lines for exactly
this reason; this guard's own tracking did not.

Also address the addendum reported on the same issue: a `<<WORD`-shaped
substring sitting inside an ordinary quoted string (not a real heredoc
opener) no longer opens the tracker either, via a naive quote-toggle scan
(`_in_quotes_before`) that stays conservative in the direction that
matters here -- under-detecting a real opener is safe for this tracker,
since a false positive is what silently swallows the rest of the file. An
opener that is never closed is now reported as an offense instead of
silently skipping everything after it.

Add tests pinning both failure modes (and their positive controls) to
tests/test_release_branch_check_898.py, alongside the existing heredoc-
tracking tests for this same function.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…naive toggle

Self-review finding (Explore reviewer): the first version of `_in_quotes_before`
toggled on any single/double-quote character with no pairing check, so a lone,
unmatched apostrophe from an ordinary English contraction ("it's", "don't")
earlier on a line could flip the toggle on and never off -- misreading a REAL
heredoc opener later on the same line as "inside quotes" and silently skipping
it. That is exactly the failure direction #981 set out to eliminate, just
reached through a different trigger.

Rewritten to match only COMPLETE quoted spans (both quote characters present)
via a regex scan, so a lone apostrophe forms no span and cannot swallow a real
opener. Added a regression test
(test_an_unmatched_apostrophe_before_a_real_opener_does_not_suppress_it) pinning
the fixed shape.

Logged a related, lower-severity, pre-existing limitation surfaced by the same
self-review round (the auditor spawn) to trap.d/981.heredoc-quote-scan-is-
escape-blind.md rather than fixing it here: the complete-span match has no
backslash-escape awareness, so a backslash-escaped quote inside a real quoted
string can still close a span one character early. Confirmed this is NOT a
regression from this commit's own rewrite -- the original naive-toggle version
produced the identical wrong answer on the same reproduction. Ranked
non-blocking (misreports) against the release ranking table; not exercised by
any file currently shipped in this repo.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit 72aa64f into main Oct 8, 2026
19 checks passed
@fdaviddpt
fdaviddpt deleted the fix/981 branch October 8, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

release-tree URL-host-in-comment guard: heredoc tracking does not skip comment lines, can silently disable the guard

1 participant