Skip to content

Commit

Permalink
Escape CSS IDs correctly for SoupSieve
Browse files Browse the repository at this point in the history
Fixes an instance of #61 in getLink().
  • Loading branch information
mgedmin committed Jun 26, 2019
1 parent 5d6f7b2 commit 147583e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ CHANGES
- Fix a bug where clicking the selected radio button would unselect it. See
`issue 68 <https://github.com/zopefoundation/zope.testbrowser/issues/68>`_.

- Fix another incompatibility with BeautifulSoup4 >= 4.7 that could result
in a SyntaxError from browser.getLink(). See `issue 61
<https://github.com/zopefoundation/zope.testbrowser/issues/61>`_.


5.3.2 (2019-02-06)
------------------
Expand Down
5 changes: 3 additions & 2 deletions src/zope/testbrowser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from zope.cachedescriptors.property import Lazy
from wsgiproxy.proxies import TransparentProxy
from bs4 import BeautifulSoup
from soupsieve import escape as css_escape

from zope.testbrowser import interfaces
from zope.testbrowser._compat import httpclient, PYTHON2
Expand Down Expand Up @@ -313,8 +314,8 @@ def _setResponse(self, response):

def getLink(self, text=None, url=None, id=None, index=0):
"""See zope.testbrowser.interfaces.IBrowser"""
qa = 'a' if id is None else 'a#%s' % id
qarea = 'area' if id is None else 'area#%s' % id
qa = 'a' if id is None else 'a#%s' % css_escape(id)
qarea = 'area' if id is None else 'area#%s' % css_escape(id)
html = self._html
links = html.select(qa)
links.extend(html.select(qarea))
Expand Down

0 comments on commit 147583e

Please sign in to comment.