Skip to content

Commit fd01124

Browse files
Jeffrey-Limasottile
authored andcommitted
Extend check for illegal Windows filenames
1 parent 515e8b3 commit fd01124

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

.pre-commit-hooks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
minimum_pre_commit_version: 3.2.0
4545
- id: check-illegal-windows-names
4646
name: check illegal windows names
47-
entry: Illegal windows filenames detected
47+
entry: Illegal Windows filenames detected
4848
language: fail
49-
files: '(?i)((^|/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|/|$)|:)'
49+
files: '(?i)((^|/)(CON|PRN|AUX|NUL|COM[\d¹²³]|LPT[\d¹²³])(\.|/|$)|[<>:\"\\|?*\x00-\x1F]|/[^/]*[\.\s]/|[^/]*[\.\s]$)'
5050
- id: check-json
5151
name: check json
5252
description: checks json files for parseable syntax.

tests/check_illegal_windows_names_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ def hook_re():
3030
pytest.param('com7.dat', id='com with digit'),
3131
pytest.param(':', id='bare colon'),
3232
pytest.param('file:Zone.Identifier', id='mid colon'),
33+
pytest.param('path/COM¹.json', id='com with superscript'),
34+
pytest.param('dir/LPT³.toml', id='lpt with superscript'),
35+
pytest.param('with < less than', id='with less than'),
36+
pytest.param('Fast or Slow?.md', id='with question mark'),
37+
pytest.param('with "double" quotes', id='with double quotes'),
38+
pytest.param('with_null\x00byte', id='with null byte'),
39+
pytest.param('ends_with.', id='ends with period'),
40+
pytest.param('ends_with ', id='ends with space'),
41+
pytest.param('ends_with\t', id='ends with tab'),
42+
pytest.param('dir/ends./with.txt', id='directory ends with period'),
43+
pytest.param('dir/ends /with.txt', id='directory ends with space'),
3344
),
3445
)
3546
def test_check_illegal_windows_names_matches(hook_re, s):
@@ -42,6 +53,10 @@ def test_check_illegal_windows_names_matches(hook_re, s):
4253
pytest.param('README.md', id='standard file'),
4354
pytest.param('foo.aux', id='as ext'),
4455
pytest.param('com.dat', id='com without digit'),
56+
pytest.param('.python-version', id='starts with period'),
57+
pytest.param(' pseudo nan', id='with spaces'),
58+
pytest.param('!@#$%^&;=≤\'~`¡¿€🤗', id='with allowed characters'),
59+
pytest.param('path.to/file.py', id='standard path'),
4560
),
4661
)
4762
def test_check_illegal_windows_names_does_not_match(hook_re, s):

0 commit comments

Comments
 (0)