Skip to content

fix: substring() swaps args when start > end per js spec#270

Merged
cs01 merged 3 commits intomainfrom
fix/substring-swap
Mar 12, 2026
Merged

fix: substring() swaps args when start > end per js spec#270
cs01 merged 3 commits intomainfrom
fix/substring-swap

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 12, 2026

Summary

  • "ABCDE".substring(3, 1) now correctly returns "BC" instead of empty string
  • Per JS spec, substring() should swap start/end when start > end, and clamp negatives to 0
  • Previously, negative length from end - start when start > end caused empty/wrong results

Test plan

  • New test fixture string-substring-swap.ts covers swapped args, equal args, single arg
  • npm run verify:quick passes (tests + Stage 1 self-hosting)

🤖 Generated with Claude Code

@cs01 cs01 merged commit 8fad1e2 into main Mar 12, 2026
12 checks passed
@cs01 cs01 deleted the fix/substring-swap branch March 12, 2026 04:54
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.

1 participant