Repository navigation
fix: honor the characters argument of strip/lstrip/rstrip (#35) - #116
Merged
Merged
Conversation
strip("chars") ignored its argument and lstrip/rstrip were not
registered, so all three returned the value unchanged. They now follow
Python's str.strip/lstrip/rstrip(chars): the argument is a set of
characters; without one, whitespace is removed. The chain() inline
fallback delegates to the same functions.
strip('"') still passed an empty string: parseArguments ran quoted
arguments through resolveVariable, whose quote-trimming removed the
quote character that was the argument's content. Quoted arguments now
only get the vars lookup.
The #36 repro used rstrip(","), which is now a native function; it
uses swapcase instead so it keeps covering the str-method fallback.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
roc-ops
force-pushed
the
fix/35-strip-chars
branch
from
November 28, 2026 01:42
109b8dc to
0dbed4d
Compare
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.
Summary
strip("chars"),lstrip("chars")andrstrip("chars")now behave like Python'sstr.strip/lstrip/rstrip(chars): the argument is a set of characters, not a substring.Three causes:
strip(internal/functions/match/functions.go) always calledstrings.TrimSpaceand ignoredargs.lstrip/rstripweren't registered, so they were skipped like any unknown function (Unknown match-variable functions are silently skipped (TTP falls back to Python str methods) #36). They're now registered. Thechain()inline fallback inmore.gocalls the same three functions.strip('"')(used in TTP'stest_issue_50andtest_slack_answer_3) still passed an empty string.parseArguments(internal/compiled/runtime.go) removes a quoted argument's quotes, then sent it throughresolveVariable, which trims"'again. That trim deleted the"that was the argument itself. Quoted arguments now get only the<vars>lookup (newresolveArgument). Unquoted arguments are handled as before.Evidence
New
internal/functions/match/strip_test.gocovers the registered functions and thechain()fallback: set semantics (strip(")("),strip("xy")), no argument, an empty argument, and argument chars that aren't at the ends. Before the fix it failed withlstrip is not registeredand 14 wrong values.New
TestParseArgumentscases:'"'→","'"→','"a"'→"a". Before the fix these parsed as"",""anda.ttpsuite:
issue35_strip_characters_argumentpasses, so its entry is removed. The two suite cases filed under strip/lstrip/rstrip ignore their characters argument #35 now strip their quotes and fail later, so their entries point at the next difference:test_issue_50→ Indented template lines match data at any indentation #30 (anaddressline also matches the deeper ipv6addressline) andtest_slack_answer_3→ TTP compat: Nested-section templates from TTP answers diverge; root cause not isolated #100 (theospf3lines join the siblingospfrecord). The README counts are updated to match.go vet,go test ./...andgo test -race(withouttest/memory,GOTTP_PYTHONset to TTP 0.10.1), staticcheck 2025.1.1 andGOOS=js GOARCH=wasm go buildall pass locally.Merge Danger
issue36_unknown_function_falls_back_to_str_methodusedrstrip(","). Becauserstripis now a real function, that repro would pass and stop covering Unknown match-variable functions are silently skipped (TTP falls back to Python str methods) #36. It now usesswapcaseinstead, and its expectation was re-recorded withrecord.py expecton TTP 0.10.1 (aBc→AbC). Unknown match-variable functions are silently skipped (TTP falls back to Python str methods) #36 is still open.parseArgumentschange affects every match function, not onlystrip. It matters only when a quoted argument starts and ends with a quote character, as in'"',"'"or'"x"'. Those arguments used to lose their quotes and now keep them, as Python does.CHANGELOG.md[Unreleased]and the same rows oftest/ttpsuite/README.md. Keep both sides. With both PRs merged,test_answers_and_docs/test_issue_50passes: this PR points it at Indented template lines match data at any indentation #30, and fix: match an indented template line's indent exactly (#30) #125 fixes Indented template lines match data at any indentation #30. The PR that merges second must delete that entry fromknown_failures.json. Combined result: suite pass 49 / skipped-by-issue 147 / design 4, repros pass 3 / 7.unicode.IsSpace. Python also strips\x1c–\x1f, which Go doesn't. That difference was already there and is unchanged.Fixes #35
🤖 Generated with Claude Code