Make to_xpath stringize a non-string operand as the standard filters do.

This commit is contained in:
Akinori MUSHA 2014-08-28 20:34:59 +09:00
parent d378795176
commit 4c938f14e5
2 changed files with 6 additions and 1 deletions

View file

@ -52,7 +52,7 @@ module LiquidInterpolatable
# Escape a string for use in XPath expression
def to_xpath(string)
subs = string.scan(/\G(?:\A\z|[^"]+|[^']+)/).map { |x|
subs = string.to_s.scan(/\G(?:\A\z|[^"]+|[^']+)/).map { |x|
case x
when /"/
%Q{'#{x}'}

View file

@ -53,5 +53,10 @@ describe LiquidInterpolatable::Filters do
@filter.to_xpath_roundtrip(string).should == string
}
end
it 'should stringize a non-string operand' do
@filter.to_xpath_roundtrip(nil).should == ''
@filter.to_xpath_roundtrip(1).should == '1'
end
end
end