Skip to content

Commit

Permalink
Do not parse html if there is no <base> tag in response body
Browse files Browse the repository at this point in the history
Saves 15% of time testing README.txt
  • Loading branch information
kedder committed Mar 20, 2013
1 parent 83f306f commit df5b346
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/zope/testbrowser/browser.py
Expand Up @@ -322,12 +322,18 @@ def follow(self, *args, **kw):

def _getBaseUrl(self):
# Look for <base href> tag and use it as base, if it exists
bases = self._response.html.find_all('base')
if bases:
return bases[0]['href']
url = self._response.request.url
if b"<base" not in self._response.body:
return url

# If no base tags found, use last request url as a base
return self._response.request.url
# we suspect there is a base tag in body, try to find href there
html = self._response.html
if not html.head:
return url
base = html.head.base
if not base:
return url
return base['href'] or url

def getForm(self, id=None, name=None, action=None, index=None):
"""See zope.testbrowser.interfaces.IBrowser"""
Expand Down

0 comments on commit df5b346

Please sign in to comment.