From d5aac2323f09e3e17e9b63aa58d997a3540617c4 Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 21 Sep 2011 15:33:30 -0400 Subject: [PATCH] _path_fixer for :// collapsing to :/ --- oyster/web.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/oyster/web.py b/oyster/web.py index aa5a7dd..26f38a7 100644 --- a/oyster/web.py +++ b/oyster/web.py @@ -17,6 +17,12 @@ class JSONEncoder(json.JSONEncoder): else: return super(JSONEncoder, self).default(obj) +def _path_fixer(url): + """ this exists because werkzeug seems to collapse // into / sometimes + certainly a hack, but given that werkzeug seems to only do the mangling + *sometimes* being a bit aggressive was the only viable option + """ + return re.sub(r'(http|https|ftp):/([^/])', r'\1://\2', url) def api_wrapper(template=None): def wrapper(func): @@ -78,12 +84,14 @@ def tracked(): @app.route('/tracked/') def tracked_view(url): + url = _path_fixer(url) doc = client.db.tracked.find_one({'url': url}) return json.dumps(doc, cls=JSONEncoder) @app.route('/doc//') def show_doc(url, version): + url = _path_fixer(url) if version == 'latest': version = -1 doc = client.get_version(url, version)