Skip to content

Commit

Permalink
finder: escape [ in pattern
Browse files Browse the repository at this point in the history
We only use *, so add necessary escaping.

Fixes WEBLATE-504
  • Loading branch information
nijel committed Oct 17, 2023
1 parent 43454eb commit 8075015
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog

* Not yet released.
* Fixed detection UTF-16 Strings files.
* Fixed detection of files with some special chars.

2.15
----
Expand Down
2 changes: 2 additions & 0 deletions translation_finder/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def has_dir(self, name: str):

def mask_matches(self, mask: str):
"""Return all mask matches."""
# Avoid dealing [ as a special char
mask = mask.replace("[", "[[]").replace("?", "[?]")
for name, path in self.files:
if fnmatch(name, mask):
yield path
Expand Down
21 changes: 21 additions & 0 deletions translation_finder/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,27 @@ def test_basic(self):
],
)

def test_shell_chars(self):
discovery = JSONDiscovery(
self.get_finder(
[
"src/app/[locale]/_translations/en.json",
"src/app/[locale]/_translations/de.json",
"src/app/[locale]/_translations/cs.json",
]
)
)
self.assert_discovery(
discovery.discover(),
[
{
"filemask": "src/app/[locale]/_translations/*.json",
"file_format": "json-nested",
"template": "src/app/[locale]/_translations/en.json",
},
],
)

def test_json_data(self):
"""
Test discovery on huge list of JSON files.
Expand Down

0 comments on commit 8075015

Please sign in to comment.