Skip to content

Commit 62e369b

Browse files
committed
Fix extension in url support
Make error cases: .jon return errors in tests. I must not have tested the prior checkin. This limits length of extension to under 6 characters. This allows most mime types (including .vcard maybe for downloading a users record) likley to be specified for download. It also permits JWT though.
1 parent 45f5645 commit 62e369b

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

CHANGES.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Fixed:
3131
encoded/compressed. (John Rouillard)
3232
- In REST interface do not raise UsageError for invalid api version.
3333
Return json error with proper message. Fixes crash. (John Rouillard)
34-
- In REST interface, only allow .json or .xml (if supported) as
35-
extensions. All other paths with a . in then will be passed through
34+
- In REST interface, allow extensions on URI less than 6 characters in
35+
length. All other paths with a . in then will be passed through
3636
without change. This allows items like a JWT to be passed as a path
3737
element. (John Rouillard)
3838

roundup/rest.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,9 +1961,12 @@ def dispatch(self, method, uri, input):
19611961
# default (application/json)
19621962
ext_type = os.path.splitext(urlparse(uri).path)[1][1:]
19631963

1964-
# Use explicit list of extensions. Even if xml isn't supported
1965-
# recognize it as a valid directive.
1966-
if ext_type in ['json', 'xml']:
1964+
# Check to see if the length of the extension is less than 6.
1965+
# this allows use of .vcard for a future use in downloading
1966+
# user info. It also allows passing through larger items like
1967+
# JWT that has a final component > 6 items. This method also
1968+
# allow detection of mistyped types like jon for json.
1969+
if ext_type and (len(ext_type) < 6):
19671970
# strip extension so uri make sense
19681971
# .../issue.json -> .../issue
19691972
uri = uri[:-(len(ext_type) + 1)]
@@ -1976,11 +1979,6 @@ def dispatch(self, method, uri, input):
19761979
# with invalid values.
19771980
data_type = ext_type or accept_type or headers.get('Accept') or "invalid"
19781981

1979-
if (ext_type):
1980-
# strip extension so uri make sense
1981-
# .../issue.json -> .../issue
1982-
uri = uri[:-(len(ext_type) + 1)]
1983-
19841982
# add access-control-allow-* to support CORS
19851983
self.client.setHeader("Access-Control-Allow-Origin", "*")
19861984
self.client.setHeader(

0 commit comments

Comments
 (0)