From 604d0d933746ee0a8ac54f96bffe7e8c3854d986 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sun, 30 Aug 2015 18:30:04 +0200 Subject: [PATCH] Case insensitive matching of nodes This re-applies the patch added in #134 to the new XPath compiler. Fixes #135. --- lib/oga/xpath/compiler.rb | 5 ++++- spec/oga/xpath/compiler/paths_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/oga/xpath/compiler.rb b/lib/oga/xpath/compiler.rb index 0809651..940a093 100644 --- a/lib/oga/xpath/compiler.rb +++ b/lib/oga/xpath/compiler.rb @@ -1398,9 +1398,12 @@ module Oga ns, name = *ast condition = nil + name_str = string(name) + zero = literal(0) if name != STAR - condition = input.name.eq(string(name)) + condition = input.name.eq(name_str) + .or(input.name.casecmp(name_str).eq(zero)) end if ns and ns != STAR diff --git a/spec/oga/xpath/compiler/paths_spec.rb b/spec/oga/xpath/compiler/paths_spec.rb index 1d3c197..0b4745d 100644 --- a/spec/oga/xpath/compiler/paths_spec.rb +++ b/spec/oga/xpath/compiler/paths_spec.rb @@ -16,6 +16,12 @@ describe Oga::XPath::Compiler do end end + describe '/A' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set(@a1) + end + end + describe '/' do it 'returns a NodeSet' do evaluate_xpath(@document).should == node_set(@document)