Repository navigation
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #981.
_check_url_in_comment's heredoc-open tracking ran_HEREDOC_OPENagainst 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_heredocalready 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:
<<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;Self-review
Two reviewers ran after the first commit. One finding was fixed in a second commit: the original
_in_quotes_beforeused 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 stashthe 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 fullpytestsuite was not run locally.Docs
README.mdnever documented this internal CI guard's own regex-matching mechanism, so nothing there needed updating.[AI-generated]