Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes regression where regular expressions containing a '?' are not p… #184

Merged
merged 1 commit into from Aug 31, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion flask_cors/core.py
Expand Up @@ -246,9 +246,10 @@ def probably_regex(maybe_regex):
if isinstance(maybe_regex, RegexObject):
return True
else:
common_regex_chars = ['*','\\',']', '?']
# Use common characters used in regular expressions as a proxy
# for if this string is in fact a regex.
return any((c in maybe_regex for c in ['*','\\',']']))
return any((c in maybe_regex for c in common_regex_chars))

def re_fix(reg):
"""
Expand Down
1 change: 1 addition & 0 deletions tests/core/helper_tests.py
Expand Up @@ -90,3 +90,4 @@ def test_probably_regex(self):
self.assertFalse(probably_regex("http://example.com"))
self.assertTrue(probably_regex("http://[\w].example.com"))
self.assertTrue(probably_regex("http://\w+.example.com"))
self.assertTrue(probably_regex("https?://example.com"))
11 changes: 11 additions & 0 deletions tests/decorator/test_origins.py
Expand Up @@ -76,6 +76,11 @@ def test_regex_list():
def test_regex_mixed_list():
return ''

@self.app.route('/test_multiple_protocols')
@cross_origin(origins="https?://example.com")
def test_multiple_protocols():
return ''

def test_defaults_no_origin(self):
''' If there is no Origin header in the request, the
Access-Control-Allow-Origin header should be '*' by default.
Expand Down Expand Up @@ -188,6 +193,12 @@ def test_regex_mixed_list(self):
self.assertEquals("http://example.com",
self.get('/test_regex_mixed_list', origin='http://example.com').headers.get(ACL_ORIGIN))

def test_multiple_protocols(self):
import logging
logging.getLogger('flask_cors').level = logging.DEBUG
resp = self.get('test_multiple_protocols', origin='https://example.com')
self.assertEqual('https://example.com', resp.headers.get(ACL_ORIGIN))


if __name__ == "__main__":
unittest.main()