Commit ba135b2
Fixed a critical bug where branch names containing slashes would be
duplicated in GitHub URLs during pull request link validation.
## The Problem
When a branch name like "release-please/branches/main" contained the
base branch name as a substring, the greedy regex pattern would
incorrectly match and duplicate the branch path:
- Bad: /blob/release-please/branches/release-please/branches/main/file.md
- Good: /blob/release-please/branches/main/file.md
The root cause was the regex pattern `(/.*/)(main)/(.*)` which greedily
matched `/blob/release-please/branches/` as the first capture group,
then when replacing with the full head ref, it duplicated the path.
## The Fix
1. **More specific regex**: Changed from `(/.*/)(${GITHUB_BASE_REF})/(.*)`
to `/(blob|tree)/(${escapedBaseRef})/(.*)` to only match `/blob/` or
`/tree/` specifically, preventing greedy matching of branch name parts
2. **Regex escaping**: Added proper escaping for special characters in
branch names (dots, asterisks, etc.) so patterns like `v1.0.0` work
3. **Proper capture groups**: Preserves whether it's a blob or tree URL
in the replacement
## Tests Added (5 new comprehensive tests)
- Branch names with slashes (release-please/branches/main)
- Branch names with multiple slashes (feature/deep/nested/branch)
- URLs already on head branch (regression test for exact bug scenario)
- Branch names with special regex characters (v1.0.0)
- Tree URLs in addition to blob URLs
All 20 tests passing with 98.68% coverage.
Fixes #85
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <[email protected]>
1 parent 3b63c81 commit ba135b2
File tree
6 files changed
+630
-6
lines changed- dist
- src
- test
- fixtures
6 files changed
+630
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35907 | 35907 | | |
35908 | 35908 | | |
35909 | 35909 | | |
| 35910 | + | |
| 35911 | + | |
35910 | 35912 | | |
35911 | 35913 | | |
35912 | | - | |
| 35914 | + | |
35913 | 35915 | | |
35914 | | - | |
| 35916 | + | |
35915 | 35917 | | |
35916 | 35918 | | |
35917 | 35919 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
78 | 85 | | |
79 | 86 | | |
80 | | - | |
| 87 | + | |
81 | 88 | | |
82 | | - | |
| 89 | + | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
0 commit comments