From 7fd92d37a9122ac65b02e4deaf3f31679c650689 Mon Sep 17 00:00:00 2001 From: Rose Davidson Date: Tue, 13 Mar 2018 11:35:36 -0700 Subject: [PATCH] Revert "Make trailing slash truly optional. (#142) (#143)" This reverts commit 818c9252583fcdf3f3896dc5d2f7dc43ecd48f36. Reverted because the author told me he'd found this produces parsing issues: > It seems now patterns like /prefix/{var1}/{var2}/ and /prefix/{var1}/ are mixed up. May reconsider this approach later. --- endpoints/api_config_manager.py | 6 +----- endpoints/test/api_config_manager_test.py | 20 -------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/endpoints/api_config_manager.py b/endpoints/api_config_manager.py index 3512702..525a876 100644 --- a/endpoints/api_config_manager.py +++ b/endpoints/api_config_manager.py @@ -317,11 +317,7 @@ def replace_variable(match): pattern = re.sub('(/|^){(%s)}(?=/|$|:)' % _PATH_VARIABLE_PATTERN, replace_variable, pattern) - if pattern.endswith('/'): - pattern += '?$' - else: - pattern += '/?$' - return re.compile(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. diff --git a/endpoints/test/api_config_manager_test.py b/endpoints/test/api_config_manager_test.py index 37a9694..9a45e07 100644 --- a/endpoints/test/api_config_manager_test.py +++ b/endpoints/test/api_config_manager_test.py @@ -264,26 +264,6 @@ 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):