fix(_utils): move hyphens to start of character classes in parseGitURI regex#256
fix(_utils): move hyphens to start of character classes in parseGitURI regex#256terminalchai wants to merge 1 commit intounjs:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR fixes a regex robustness issue in the Git URI parser by moving dashes to the start of character classes in both the repo and ref segments, ensuring they're treated as literal characters rather than potential range operators. Test cases validate hyphenated owner/repo names and refs parse correctly. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Closes #183
The
inputRegexinsrc/_utils.tshad hyphens positioned inside character classes in ways that, while technically valid in ES5 mode, are ambiguous and can cause issues in strict Unicode mode (u/vflags) or with stricter regex linters:In
[\w.-], the sequence.-looks like a range (though-at end-of-class is treated as a literal in practice). In[\w./@-], similarly@-before]is ambiguous to readers and tooling.Fix
Move the hyphen to the start of each character class, where it is unambiguously a literal hyphen in all regex modes — no escape needed, no linter warning:
This is the idiomatic JavaScript pattern (MDN, ECMAScript spec) for a literal hyphen inside
[].Tests
Added two regression cases to
test/utils.test.tsthat exercise hyphens in the owner/repo name and branch ref:my-org/my-repo→{ repo: "my-org/my-repo" }my-org/my-repo#fix/MY-123→{ repo: "my-org/my-repo", ref: "fix/MY-123" }All 11 tests pass, oxlint 0 warnings/errors, oxfmt clean,
tsgo --noEmitclean, build clean.Summary by CodeRabbit