sparklemotion / nokogiri

Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby.
https://nokogiri.org/
MIT License
6.15k stars 897 forks source link

CSS case insensitive attribute selector operator #2036

Open Juice10 opened 4 years ago

Juice10 commented 4 years ago

Describe the bug

When using .css(input[type=checkbox i] Nokogiri kicks up an error: Nokogiri::CSS::SyntaxError (unexpected ' ' after '[:equal, "checkbox"]')

To Reproduce

#! /usr/bin/env ruby

require 'nokogiri'
require 'minitest/autorun'

class Test < MiniTest::Spec
  describe "Node#css" do
    it "should find a div using chained classes" do
      html = <<~HEREDOC
        <html>
          <body>
            <input type="CHECKBOX" />
      HEREDOC

      doc = Nokogiri::HTML::Document.parse(html)

      assert_equal 1, doc.css("input[type=checkbox i]").length
    end
  end
end

Expected behavior

The i modifier should make the attribute selector case-insensitive.

Environment

# Nokogiri (1.10.9)
    ---
    warnings: []
    nokogiri: 1.10.9
    ruby:
      version: 2.7.1
      platform: x86_64-darwin19
      description: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
      engine: ruby
    libxml:
      binding: extension
      source: system
      compiled: 2.9.4
      loaded: 2.9.4

Additional context

More information on attribute selector operators: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

flavorjones commented 4 years ago

Hi, @Juice10! Thanks for opening this issue.

Unfortunately, it looks like we have never tried to add support for the case-sensitivity attribute selectors. This is relatively new, in Selectors Level 4 which is still in draft (although we're probably all familiar with how that works).

I'm unlikely to work on adding this support while I'm still trying to get v1.11.0 out the door, but I'll prioritize it after that. In the meantime, if you have time to work on this, I'd be super happy to help you craft a PR!

flavorjones commented 4 months ago

It seems likely we'll be able to deliver this as part of the CSS selector rewrite (see #2560) which is scheduled to land in v2.0.