Skip to content

Commit cfc3672

Browse files
authored
Merge pull request #582 from jack1142/allow_any_branch_name
Disallow any branch name in checks_vcs_permalinks
2 parents 4195f4d + 4729918 commit cfc3672

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pre_commit_hooks/check_vcs_permalinks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99

1010
def _get_pattern(domain: str) -> Pattern[bytes]:
11-
regex = rf'https://{domain}/[^/ ]+/[^/ ]+/blob/master/[^# ]+#L\d+'
11+
regex = (
12+
rf'https://{domain}/[^/ ]+/[^/ ]+/blob/'
13+
r'(?![a-fA-F0-9]{4,64}/)([^/. ]+)/[^# ]+#L\d+'
14+
)
1215
return re.compile(regex.encode())
1316

1417

tests/check_vcs_permalinks_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def test_passing(tmpdir):
1111
f.write_binary(
1212
# permalinks are ok
1313
b'https://github.com/asottile/test/blob/649e6/foo%20bar#L1\n'
14+
# tags are ok
15+
b'https://github.com/asottile/test/blob/1.0.0/foo%20bar#L1\n'
1416
# links to files but not line numbers are ok
1517
b'https://github.com/asottile/test/blob/master/foo%20bar\n'
1618
# regression test for overly-greedy regex
@@ -23,14 +25,16 @@ def test_failing(tmpdir, capsys):
2325
with tmpdir.as_cwd():
2426
tmpdir.join('f.txt').write_binary(
2527
b'https://github.com/asottile/test/blob/master/foo#L1\n'
26-
b'https://example.com/asottile/test/blob/master/foo#L1\n',
28+
b'https://example.com/asottile/test/blob/master/foo#L1\n'
29+
b'https://example.com/asottile/test/blob/main/foo#L1\n',
2730
)
2831

2932
assert main(('f.txt', '--additional-github-domain', 'example.com'))
3033
out, _ = capsys.readouterr()
3134
assert out == (
3235
'f.txt:1:https://github.com/asottile/test/blob/master/foo#L1\n'
3336
'f.txt:2:https://example.com/asottile/test/blob/master/foo#L1\n'
37+
'f.txt:3:https://example.com/asottile/test/blob/main/foo#L1\n'
3438
'\n'
3539
'Non-permanent github link detected.\n'
3640
'On any page on github press [y] to load a permalink.\n'

0 commit comments

Comments
 (0)