From 9eecd4f49089665804802ac767ce4e1d4466f542 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 4 Dec 2018 15:24:27 +0000 Subject: [PATCH] Make Item.from_external() more robust. --- sourcing/model.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sourcing/model.py b/sourcing/model.py index ac5bf17..d6b2820 100644 --- a/sourcing/model.py +++ b/sourcing/model.py @@ -240,13 +240,18 @@ span: {},start=0,length={}'''.format(self.external_url, title_source_doc.externa @classmethod def from_external(cls, url, home=None): base = current_app.config.get('BASE_URL') + username, hashid = None, None if home is None: home = url_for('view.home', _external=True) if url.startswith(home): username, _, hashid = url[len(home):].partition('/') elif base and url.startswith(base): username, _, hashid = url[len(base):].lstrip('/').partition('/') - else: + + if username and '/' in username or hashid and '/' in hashid: + username, hashid = None, None + + if not username or not hashid: m = re_server_url.match(url) if not m: return