-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xpath abbreviate: add support for string literal that contains double-quote #96
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -363,6 +363,18 @@ def Predicate path, parsed | |||
path | |||
end | |||
|
|||
def QuoteLiteral literal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use snake_case
?
def QuoteLiteral literal | |
def quote_literal(literal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
literal.inspect | ||
end | ||
end | ||
|
||
private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this private
above quote_literal
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: d6a02b9
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