Skip to content

fix: add bounds checking to substr for negative/out-of-range start#250

Merged
cs01 merged 1 commit intomainfrom
fix/substr-bounds-check
Mar 11, 2026
Merged

fix: add bounds checking to substr for negative/out-of-range start#250
cs01 merged 1 commit intomainfrom
fix/substr-bounds-check

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 11, 2026

Summary

  • substr() with negative start index (e.g. "hello".substr(-3)) now correctly wraps around instead of reading out-of-bounds memory
  • Start indices beyond string length now return empty string instead of accessing invalid memory
  • Same clamping pattern as slice() — handles negative, too-small, and too-large indices

Test plan

  • New substr-bounds.ts fixture covering: basic, negative start, very negative, past end, mid, length too long
  • npm run verify:quick passes (tests + self-hosting)

🤖 Generated with Claude Code

…t index

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cs01 cs01 merged commit 9d6bc66 into main Mar 11, 2026
12 checks passed
@cs01 cs01 deleted the fix/substr-bounds-check branch March 12, 2026 05:35
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