Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.
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
6 changes: 5 additions & 1 deletion endpoints/api_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ def replace_variable(match):

pattern = re.sub('(/|^){(%s)}(?=/|$|:)' % _PATH_VARIABLE_PATTERN,
replace_variable, pattern)
return re.compile(pattern + '/?$')
if pattern.endswith('/'):
pattern += '?$'
else:
pattern += '/?$'
return re.compile(pattern)

def _save_rpc_method(self, method_name, version, method):
"""Store JsonRpc api methods in a map for lookup at call time.
Expand Down
20 changes: 20 additions & 0 deletions endpoints/test/api_config_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,26 @@ def test_trailing_slash_optional(self):
self.assertEqual(fake_method, method_spec)
self.assertEqual({}, params)

def test_trailing_slash_could_be_omitted(self):
# Create a get resource URL with trailing slash.
fake_method = {'httpMethod': 'GET', 'path': 'with-trailing-slash/'}
self.config_manager._save_rest_method('guestbook_api.withtrailingslash',
'guestbook_api', 'v1', fake_method)

# Make sure we get the method when we query with a slash.
method_name, method_spec, params = self.config_manager.lookup_rest_method(
'guestbook_api/v1/with-trailing-slash/', 'GET')
self.assertEqual('guestbook_api.withtrailingslash', method_name)
self.assertEqual(fake_method, method_spec)
self.assertEqual({}, params)

# Make sure we get the method when we query without a slash.
method_name, method_spec, params = self.config_manager.lookup_rest_method(
'guestbook_api/v1/with-trailing-slash', 'GET')
self.assertEqual('guestbook_api.withtrailingslash', method_name)
self.assertEqual(fake_method, method_spec)
self.assertEqual({}, params)


class ParameterizedPathTest(unittest.TestCase):

Expand Down