Using selector with multiword attribute value throws exception

Bug #1692137 reported by Thomas Hauk
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Beautiful Soup
Fix Released
Low
Unassigned

Bug Description

The following call will throw an exception

    optgroup = soup.select_one('#some_id > optgroup[label="Some Label"]')

as the recurisve call

    tokens = shlex.split(selector)

Will eventually result in a token list of `optgroup[label=Some` and `Label]`

Seems to me this is because the quotation marks are scrubbed out by shlex on the first call to it.

Tags: css
description: updated
description: updated
Revision history for this message
Leonard Richardson (leonardr) wrote :

I've confirmed this bug with the following code:

from bs4 import BeautifulSoup
BeautifulSoup("<a id="some_id">).select_one('#some_id > optgroup[label="Some Label"]')

Since the CSS selector system is contributed code, I only add to it when a patch and test are contributed. I'm going to leave this issue open in a 'confirmed' state and if someone provides a patch or pull request I'll merge it.

Changed in beautifulsoup:
status: New → Confirmed
tags: added: css
Changed in beautifulsoup:
importance: Undecided → Low
Revision history for this message
Leonard Richardson (leonardr) wrote :

In the forthcoming 4.7.0 release, all CSS selector logic is delegated to the Soup Sieve project (https://facelessuser.github.io/soupsieve/). This should dramatically improve the overall support for CSS selectors in Beautiful Soup, and provide a responsive channel for improvements.

I'm closing this issue as of the 4.7.0 release. If it's still a problem in 4.7.0, file a bug against Soup Sieve.

Changed in beautifulsoup:
status: Confirmed → Fix Committed
Revision history for this message
Leonard Richardson (leonardr) wrote :

In 4.7.0 release.

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.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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