Skip to content

fix: honor the characters argument of strip/lstrip/rstrip (#35) - #116

Merged
roc-ops merged 1 commit into
mainfrom
fix/35-strip-chars
Nov 28, 2026
Merged

roc-ops merged 1 commit into
mainfrom
fix/35-strip-chars

Conversation

@roc-ops

@roc-ops roc-ops commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

strip("chars"), lstrip("chars") and rstrip("chars") now behave like Python's str.strip/lstrip/rstrip(chars): the argument is a set of characters, not a substring.

template:  x {{ m | strip("()") }} {{ l | lstrip("(") }} {{ r | rstrip(")") }} {{ c | chain("ch") }}   (ch = "strip('()') | upper")
data:      x (00:01) ((a) (b)) ((c))

            m          l        r        c
before      (00:01)    ((a)     (b))     ((C))
after       00:01      a)       (b       C
TTP 0.10.1  00:01      a)       (b       C

Three causes:

  1. strip (internal/functions/match/functions.go) always called strings.TrimSpace and ignored args.
  2. lstrip/rstrip weren'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. The chain() inline fallback in more.go calls the same three functions.
  3. strip('"') (used in TTP's test_issue_50 and test_slack_answer_3) still passed an empty string. parseArguments (internal/compiled/runtime.go) removes a quoted argument's quotes, then sent it through resolveVariable, which trims "' again. That trim deleted the " that was the argument itself. Quoted arguments now get only the <vars> lookup (new resolveArgument). Unquoted arguments are handled as before.

Evidence

  • New internal/functions/match/strip_test.go covers the registered functions and the chain() 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 with lstrip is not registered and 14 wrong values.

  • New TestParseArguments cases: '"' → ", "'" → ', '"a"' → "a". Before the fix these parsed as "", "" and a.

  • ttpsuite:

    before after
    TTP 0.10.1 suite pass 48 / skipped-by-issue 148 / design 4 of 200 unchanged
    gottp repros pass 1 / skipped-by-issue 9 / design 0 of 10 pass 2 / skipped-by-issue 8 / design 0 of 10

    issue35_strip_characters_argument passes, 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 (an address line also matches the deeper ipv6 address line) and test_slack_answer_3 → TTP compat: Nested-section templates from TTP answers diverge; root cause not isolated #100 (the ospf3 lines join the sibling ospf record). The README counts are updated to match.

  • go vet, go test ./... and go test -race (without test/memory, GOTTP_PYTHON set to TTP 0.10.1), staticcheck 2025.1.1 and GOOS=js GOARCH=wasm go build all pass locally.

Merge Danger

Fixes #35

🤖 Generated with Claude Code

@roc-ops roc-ops added this to the Baseline v0.1.14 milestone Nov 28, 2026
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
roc-ops merged commit 5956563 into main Nov 28, 2026
3 checks passed
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.

strip/lstrip/rstrip ignore their characters argument Indented template lines match data at any indentation

1 participant