Make Item.from_external() more robust.
This commit is contained in:
parent
379ee401fe
commit
9eecd4f490
|
@ -240,13 +240,18 @@ span: {},start=0,length={}'''.format(self.external_url, title_source_doc.externa
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_external(cls, url, home=None):
|
def from_external(cls, url, home=None):
|
||||||
base = current_app.config.get('BASE_URL')
|
base = current_app.config.get('BASE_URL')
|
||||||
|
username, hashid = None, None
|
||||||
if home is None:
|
if home is None:
|
||||||
home = url_for('view.home', _external=True)
|
home = url_for('view.home', _external=True)
|
||||||
if url.startswith(home):
|
if url.startswith(home):
|
||||||
username, _, hashid = url[len(home):].partition('/')
|
username, _, hashid = url[len(home):].partition('/')
|
||||||
elif base and url.startswith(base):
|
elif base and url.startswith(base):
|
||||||
username, _, hashid = url[len(base):].lstrip('/').partition('/')
|
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)
|
m = re_server_url.match(url)
|
||||||
if not m:
|
if not m:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue