Skip to content

Commit

Permalink
Merge pull request #93 from teamcapybara/custom_attribute
Browse files Browse the repository at this point in the history
support querying HTML5 attributes with "special" characters in them
  • Loading branch information
twalpole committed Oct 15, 2018
2 parents c71de35 + 7a3fdfe commit c7d087f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/xpath/renderer.rb
Expand Up @@ -59,7 +59,11 @@ def where(on, condition)
end

def attribute(current, name)
"#{current}/@#{name}"
if valid_xml_name?(name)
"#{current}/@#{name}"
else
"#{current}/attribute::*[local-name(.) = #{string_literal(name)}]"
end
end

def binary_operator(name, left, right)
Expand Down Expand Up @@ -112,5 +116,9 @@ def with_element_conditions(expression, element_names)
"#{expression}*"
end
end

def valid_xml_name?(name)
name =~ /^[a-zA-Z_:][a-zA-Z0-9_:\.\-]*$/
end
end
end

0 comments on commit c7d087f

Please sign in to comment.