Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nokogiri should accept multiple selectors as arguments to the :not CSS pseudo-class #3207

Open
flavorjones opened this issue May 24, 2024 · 1 comment

Comments

@flavorjones
Copy link
Member

Please describe the bug

CSS pseudo-class :not should be able to accept multiple selectors as arguments:

https://developer.mozilla.org/en-US/docs/Web/CSS/:not

Raised by @stoivo in a comment in #3193

Help us reproduce what you're seeing

#! /usr/bin/env ruby

require "bundler/inline"

gemfile do
  source "https://rubygems.org"
  gem "nokogiri", path: "."
end

parser = Nokogiri::CSS::Parser.new
pp parser.parse("div:not(.one,.two)")

emits:

/home/flavorjones/code/oss/nokogiri/lib/nokogiri/css/parser_extras.rb:86:in `on_error': unexpected ',' after '#<Nokogiri::CSS::Node:0x0000756541fec678>' (Nokogiri::CSS::SyntaxError)

Expected behavior

https://developer.mozilla.org/en-US/docs/Web/CSS/:not#description says that:

You can negate several selectors at the same time. Example: :not(.foo, .bar) is equivalent to :not(.foo):not(.bar).

Given

parser.parse("div:not(.one)").first.to_xpath("//", Nokogiri::CSS::XPathVisitor.new)
# //div[not(contains(concat(' ',normalize-space(@class),' '),' one '))]

then two selectors should transpile to

parser.parse('div:not(.foo):not(.bar)').first.to_xpath("//", Nokogiri::CSS::XPathVisitor.new)
# //div[not(contains(concat(' ',normalize-space(@class),' '),' foo ')) and not(contains(concat(' ',normalize-space(@class),' '),' bar '))]
@flavorjones flavorjones added state/needs-triage Inbox for non-installation-related bug reports or help requests topic/css and removed state/needs-triage Inbox for non-installation-related bug reports or help requests labels May 24, 2024
@flavorjones flavorjones changed the title [bug] Nokogiri should accept multiple selectors as arguments to the :not CSS pseudo-class [Nokogiri should accept multiple selectors as arguments to the :not CSS pseudo-class Jun 19, 2024
@flavorjones
Copy link
Member Author

I've updated this to be a feature, since in Selectors Level 3, :not only accepted a single argument. But I'm working on supporting some Level 4 features including this.

@flavorjones flavorjones added this to the v2.0.0 milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant