xpath abbreviate: add support for string literal that contains double-quote#96
xpath abbreviate: add support for string literal that contains double-quote#96kou merged 3 commits intoruby:masterfrom pulver:master
Conversation
kou
left a comment
There was a problem hiding this comment.
Does this work with a number literal?
|
Good catch, thank you. I restored the previous method of I wasn't sure how to handle this rexml/lib/rexml/parsers/xpathparser.rb Lines 86 to 87 in 54b7109 |
lib/rexml/parsers/xpathparser.rb
Outdated
| path | ||
| end | ||
|
|
||
| def QuoteLiteral literal |
There was a problem hiding this comment.
Could you use snake_case?
| def QuoteLiteral literal | |
| def quote_literal(literal) |
There was a problem hiding this comment.
And could you move this method to before #LocalPath (the line 192)?
Method in #LocationPath to #FunctionCall are for syntaxes in XPath. I don't want to mix this and them.
lib/rexml/parsers/xpathparser.rb
Outdated
| def QuoteLiteral literal | ||
| case literal | ||
| when String | ||
| # Xpath 1.0 does not support escape characters. |
There was a problem hiding this comment.
| # Xpath 1.0 does not support escape characters. | |
| # XPath 1.0 does not support escape characters. |
lib/rexml/parsers/xpathparser.rb
Outdated
| pattern = literal.include?('"') ? "'%s'" : '"%s"' | ||
| pattern % literal |
There was a problem hiding this comment.
Could you use string interpolation instead of String#%?
| pattern = literal.include?('"') ? "'%s'" : '"%s"' | |
| pattern % literal | |
| if literal.include?("'") | |
| "\"#{literal}\"" | |
| else | |
| "'#{literal}'" | |
| end |
* Rename QuoteLiteral -> quote_literal and move to after predicate_to_string.
* Xpath -> XPath.
* Replace %-substitution w/ String "#{...}".
|
Done, thanks for the feedback. |
lib/rexml/parsers/xpathparser.rb
Outdated
| end | ||
| end | ||
|
|
||
| private |
There was a problem hiding this comment.
Could you move this private above quote_literal?
This adds support for a string literal that contains a double-quote to
XPathParser#abbreviate. Basically any literal that contains a double-quote"must be quoted by single-quotes'since XPath 1.0 does not support any escape characters.The change improves the following test script
Output Before Change
Output After Change