Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/firebase_functions/private/path_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ class PathPattern:
segments: list[PathSegment]

def __init__(self, raw_path: str):
self.raw = raw_path
normalized_path = raw_path.strip("/")
self.raw = normalized_path
self.segments = []
self.init_path_segments(raw_path)
self.init_path_segments(normalized_path)

def init_path_segments(self, raw: str):
parts = raw.split("/")
Expand Down
22 changes: 22 additions & 0 deletions tests/test_path_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ def test_trim_param(self):
self.assertEqual(trim_param("{something=*}"), "something")

def test_extract_matches(self):
# parse single-capture segments with leading slash
pp = PathPattern("/messages/{a}/{b}/{c}")
self.assertEqual(
pp.extract_matches("messages/match_a/match_b/match_c"),
{
"a": "match_a",
"b": "match_b",
"c": "match_c",
},
)

# parse single-capture segments without leading slash
pp = PathPattern("messages/{a}/{b}/{c}")
self.assertEqual(
pp.extract_matches("messages/match_a/match_b/match_c"),
{
"a": "match_a",
"b": "match_b",
"c": "match_c",
},
)

# parse without multi-capture segments
pp = PathPattern("{a}/something/else/{b}/end/{c}")
self.assertEqual(
Expand Down