diff --git a/lib/rexml/parsers/xpathparser.rb b/lib/rexml/parsers/xpathparser.rb index afff85ce..7961e32f 100644 --- a/lib/rexml/parsers/xpathparser.rb +++ b/lib/rexml/parsers/xpathparser.rb @@ -178,7 +178,7 @@ def predicate_to_string( path, &block ) when :literal path.shift string << " " - string << path.shift.inspect + string << quote_literal(path.shift) string << " " else string << " " @@ -189,6 +189,21 @@ def predicate_to_string( path, &block ) end private + def quote_literal( literal ) + case literal + when String + # XPath 1.0 does not support escape characters. + # Assumes literal does not contain both single and double quotes. + if literal.include?("'") + "\"#{literal}\"" + else + "'#{literal}'" + end + else + literal.inspect + end + end + #LocationPath # | RelativeLocationPath # | '/' RelativeLocationPath?