Ignore negative text requirements when extracting strings from regexps

This commit is contained in:
Thomas Walpole 2019-07-24 08:25:48 -07:00
parent 7e2d19bde1
commit f1139a5985
2 changed files with 17 additions and 0 deletions

View File

@ -100,6 +100,8 @@ module Capybara
def extract_strings(process_alternatives)
strings = []
each do |exp|
next if exp.ignore?
next strings.push(nil) if exp.optional? && !process_alternatives
next strings.push(exp.alternative_strings) if exp.alternation? && process_alternatives
@ -159,6 +161,11 @@ module Capybara
alts.all?(&:any?) ? Set.new(alts) : nil
end
def ignore?
[Regexp::Expression::Assertion::NegativeLookahead,
Regexp::Expression::Assertion::NegativeLookbehind].any? { |klass| @exp.is_a? klass }
end
private
def indeterminate?

View File

@ -212,6 +212,16 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
)
end
it 'ignores negative lookaheads' do
verify_strings(
/^(?!.*\bContributing Editor\b).*$/ => %w[],
/abc(?!.*def).*/ => %w[abc],
/(?!.*def)abc/ => %w[abc],
/abc(?!.*def.*).*ghi/ => %w[abc ghi],
/abc(?!.*bcd)def/ => %w[abcdef]
)
end
it 'handles anchors' do
verify_strings(
/^abc/ => %w[abc],