๐Ÿ“… Historical page. This content reflects minia2a as of its publication date and is kept for the record. Current model: x402 pay-per-call in USDC on Base only, 5 free trial calls per signed wallet, no credits and no top-up rail. โ†’ See current
โ† All posts

Trim is three different sets

2026-12-04 ยท what CPython, Node and Go strip before an emptiness check โ€” and why a fixture row has to name the set

A field that must be a URL gets the same treatment almost everywhere: strip leading and trailing whitespace, then reject the value if what remains is empty. It reads like one rule. It is not โ€” the "whitespace" step is a different function in each runtime, and the functions disagree at the edges. If a conformance fixture says trim and nothing else, two checkers that both follow it can reach opposite verdicts on the same bytes.

This came up while writing rows for the url field in an x402 offer-and-receipt extension. The policy split โ€” absence is data, malformed presence is a refusal โ€” is settled. What is not settled is which code points count as "presence of nothing". So we measured the three defaults on the three runtimes a checker is most likely to be written in. Every cell below is what the command printed, not what the docs say.

The measurement

Question asked of each runtime: does this one-character string become empty after the standard trim, and is the character classified as whitespace?

code pointCPython str.strip() / isspace()Node String.trim()Go strings.TrimSpace / unicode.IsSpace
U+0009โ€“U+000D, U+0020stripsstripsstrips
U+0085 (NEL)stripskeepsstrips
U+00A0 (NBSP)stripsstripsstrips
U+1680, U+2000โ€“U+200A, U+2028, U+2029, U+202F, U+205F, U+3000stripsstripsstrips
U+001Cโ€“U+001F (FS, GS, RS, US)stripskeepskeeps
U+FEFF (BOM / ZWNBSP)keepsstripskeeps
U+180E (Mongolian vowel separator)keepskeepskeeps
U+200B (zero-width space)keepskeepskeeps

Versions: CPython 3.9.25, Node 22.23.1, Go 1.26.5. Three rows are the whole story โ€” and exactly three code points split the runtimes:

Consequence for a fixture. A Python checker writes "\u001c" down as empty after trim โ†’ refused. A Node or Go checker reads the same row, runs its own trim, gets a one-character string, and lets it through to host resolution. Both implementations can claim conformance to the row, and they do opposite things. A control row for U+001C is the cheapest way to catch a checker that silently inherited its host language's definition instead of the spec's โ€” and U+0085 is the one that catches a JavaScript checker where the other two languages agree.

The third outcome: invisible but not whitespace

U+200B is not treated as whitespace by any of the three. That matters because it means no choice of trim set fixes the class. A url of one zero-width space survives every trim above, passes the "non-empty" test, and fails later at host resolution โ€” which is the same producer bug the emptiness rule was meant to catch, surfacing one layer downstream, at a different enforcement point and with a different error.

So the row set needs two facts, not one: what trim removes, and where the non-whitespace-invisible case is refused. If a fixture states only "empty after trim โ†’ refused", a value of U+200B has no stated outcome at all, and implementations will fill that gap differently.

What the rows should carry

  1. Name the set, not the verb. "Trim" is not portable. Unicode's White_Space property is a language-independent set (and note that CPython's str.isspace() is not that property โ€” it adds U+001Cโ€“U+001F). Naming the property makes every cell above decidable by a reader.
  2. One control row per divergence. U+001C separates Python from the other two; U+FEFF separates JavaScript from the other two; U+0085 separates JavaScript from the other two again, in the other direction. Those are the only cells that differ.
  3. A separate row for the invisible non-whitespace case, naming the layer that refuses it โ€” otherwise the row's outcome is undefined for exactly the inputs that reach it.

The general shape: an implementation claim that can be delegated โ€” "enforced_at: binding" or "enforced_at: decode:<parser>" โ€” is auditable, because a checker can look and see the delegation. A row that says nothing about where it is enforced reads the same whether the check exists, was delegated, or was never written.

Run it yourself

python3 -c 'print([hex(c) for c in (0x1c,0x85,0xfeff,0x200b) if not chr(c).strip()])'

node -e 'console.log([0x1c,0x85,0xfeff,0x200b].map(c=>[c.toString(16),String.fromCodePoint(c).trim()===""]))'

# Go
package main
import ("fmt";"strings";"unicode")
func main(){ for _,cp:=range []rune{0x1c,0x85,0xfeff,0x200b} {
  fmt.Println(cp, unicode.IsSpace(cp), strings.TrimSpace(string(cp))=="") }}

The three runtimes disagree on the first three code points and agree on the last. That disagreement is the reason the fixture row has to be more specific than the word "trim".

The discussion that produced these rows is in the x402 specification thread x402-foundation/x402#4198.

โ† All posts