ValueError on CSS selectors with dashes

Bug #1276211 reported by Francisco Canas
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Beautiful Soup
Fix Released
Undecided
Unassigned

Bug Description

Info:
Name: beautifulsoup4
Version: 4.3.2
Location: /usr/lib/python2.7/site-packages

Description:
Calling the select() method on tags with dashes produces:

 ValueError: Unsupported or invalid CSS selector: "dashed-tag"

The find_all() method does not exhibit this behaviour, it works as expected, so I didn't think this was intended behaviour for select().

Steps to reproduce:
I have attached a short script to reproduce it.

thanks.

Revision history for this message
Francisco Canas (mailfrancisco) wrote :
Revision history for this message
Francisco Canas (mailfrancisco) wrote :

Just in case anyone is interested in adding dashed tag support to the select() method: Here's a patch showing the needed changes to elements.py and relevant unit tests.

Changed in beautifulsoup:
status: New → Fix Committed
Revision history for this message
Martijn Pieters (mjpieters) wrote :

Can this be extended to the attributes as well? `data-*` attributes always use a dash and cannot be matched with bs4 selectors.

The fix is as simple as replacing (?P<attribute>\w+) with (?P<attribute>[\w-]+)

Revision history for this message
Martijn Pieters (mjpieters) wrote :

Ah, issue 1304007 covers that case: https://bugs.launchpad.net/beautifulsoup/+bug/1304007

Changed in beautifulsoup:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.