Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

simple_selector: attributes with brackets in double quotes not recognized #2418

Closed
wants to merge 1 commit into from

6 participants

@Arsen7

simple_selector: attributes with brackets in double quotes not recognized

HTML::Selector#simple_selector can recognize attributes in single and
double quotes. But when the attribute value contains square brackets,
and the value is enclosed in double quotes, an exception
ArgumentError: Invalid selector: "] is thrown.

Related to issue #2412.

@Arsen7 Arsen7 simple_selector: attributes with brackets in double quotes not recogn…
…ized

HTML::Selector#simple_selector can recognize attributes in single and
double quotes. But when the attribute value contains square brackets,
and the value is enclosed in double quotes, an exception
`ArgumentError: Invalid selector: "]` is thrown.

Related to issue #2412.
988b6b4
@isaacsanders

@Arsen7 Is this still an issue?

@Arsen7

@isaacsanders Yes, it is. If I change the test, as shown in my diff, and run cd actionpack && rake test, then the test fails. If I apply the fix in that regular expression and run rake test, all the tests pass.

I have tested the issue on the 3-2-stable branch (pulled just 5 minutes ago). I do not have ruby1.9.

@kytrinyx

I applied this patch to master (at d08fee3) and verified that all the tests run using ruby 1.9.3-p194.

@rafaelfranca

@kytrinyx thank you. But we are going to remove the html-scanner with a better solution that will solve some issues. I'm assigning this pull request to me and will close when fixed.

@rafaelfranca rafaelfranca was assigned
@steveklabnik
Collaborator

Since this is vendored code, is it even eligible to be touched?

@carlosantoniodasilva

As far as I know, html-scanner is frozen the same was as the inflector. As @rafaelfranca said, I think we'll have to wait.

@steveklabnik
Collaborator

Right; I guess what I'm saying is, if it's not going to get changed, then why even keep the issue open?

@carlosantoniodasilva

I think @rafaelfranca wants to keep track of it. But lets ask him later.

@rafaelfranca

I'll close the issue and add it to my icebox. I know the solution but it will add another dependency to Rails, and it is the blocker now.

@steveklabnik @carlosantoniodasilva :heart:

@steveklabnik
Collaborator

Yeah. @wycats said that he'd be okay with it for Tokaido, but causing Rails to have a cext dependency is a big step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 4, 2011
  1. @Arsen7

    simple_selector: attributes with brackets in double quotes not recogn…

    Arsen7 authored
    …ized
    
    HTML::Selector#simple_selector can recognize attributes in single and
    double quotes. But when the attribute value contains square brackets,
    and the value is enclosed in double quotes, an exception
    `ArgumentError: Invalid selector: "]` is thrown.
    
    Related to issue #2412.
This page is out of date. Refresh to see the latest.
View
2  actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb
@@ -558,7 +558,7 @@ def simple_selector(statement, values, can_negate = true)
end
# Attribute value.
- next if statement.sub!(/^\[\s*([[:alpha:]][\w\-:]*)\s*((?:[~|^$*])?=)?\s*('[^']*'|"[^*]"|[^\]]*)\s*\]/) do |match|
+ next if statement.sub!(/^\[\s*([[:alpha:]][\w\-:]*)\s*((?:[~|^$*])?=)?\s*('[^']*'|"[^"]*"|[^\]]*)\s*\]/) do |match|
name, equality, value = $1, $2, $3
if value == "?"
value = values.shift
View
10 actionpack/test/controller/selector_test.rb
@@ -102,7 +102,7 @@ def test_attribute
def test_attribute_quoted
- parse(%Q{<div id="1" title="foo"></div><div id="2" title="bar"></div><div id="3" title=" bar "></div>})
+ parse(%Q{<div id="1" title="foo"></div><div id="2" title="bar"></div><div id="3" title=" bar "></div><div id="4" name="item[baz]"></div>})
# Match without quotes.
select("[title = bar]")
assert_equal 1, @matches.size
@@ -119,6 +119,14 @@ def test_attribute_quoted
select("[title = \" bar \" ]")
assert_equal 1, @matches.size
assert_equal "3", @matches[0].attributes["id"]
+ # Match brackets in single quotes.
+ select("[name = 'item[baz]' ]")
+ assert_equal 1, @matches.size
+ assert_equal "4", @matches[0].attributes["id"]
+ # Match brackets in double quotes.
+ select("[name = \"item[baz]\" ]")
+ assert_equal 1, @matches.size
+ assert_equal "4", @matches[0].attributes["id"]
end
Something went wrong with that request. Please try again.