Skip to content

Commit 4ad56d6

Browse files
joshuamortonjoshuamorton
andauthored
Fix regex sorting issue from #391 (#392)
* Rename "helper_tests.py" to "test_helpers.py". This causes it to get picked up by pytest, which makes clear the failure that I will fix in a followup commit. * Sort paths longest to shortest. Previously, path sort length was inverted, with short paths before long ones, this led to a path like `/*` being handled *before* a path like `/foo/bar/baz`, which is exactly what we didn't want. This was tested, but the test was misnamed and so wasn't picked up by pytest. --------- Co-authored-by: joshuamorton <[email protected]>
1 parent 35d8753 commit 4ad56d6

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

flask_cors/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ def parse_resources(resources):
7373
def sort_key(pair):
7474
pattern, _ = pair
7575
if isinstance(pattern, RegexObject):
76-
return (1, 0, pattern.pattern.count("/"), -len(pattern.pattern))
76+
return (1, 0, -pattern.pattern.count("/"), -len(pattern.pattern))
7777
elif probably_regex(pattern):
78-
return (1, 1, pattern.count("/"), -len(pattern))
78+
return (1, 1, -pattern.count("/"), -len(pattern))
7979
else:
80-
return (0, 0, pattern.count("/"), -len(pattern))
80+
return (0, 0, -pattern.count("/"), -len(pattern))
8181

8282
return sorted(resources, key=sort_key)
8383

File renamed without changes.

0 commit comments

Comments
 (0)