post queries: support single-quoted strings in metatags.
This commit is contained in:
@@ -358,7 +358,7 @@ class PostQuery
|
|||||||
def quoted_value
|
def quoted_value
|
||||||
return nil unless metatag?
|
return nil unless metatag?
|
||||||
|
|
||||||
if value.include?(" ") || value.starts_with?('"') || value.empty?
|
if value.include?(" ") || value.starts_with?('"') || value.starts_with?("'") || value.empty?
|
||||||
%Q{"#{value.gsub(/"/, '\\"')}"}
|
%Q{"#{value.gsub(/"/, '\\"')}"}
|
||||||
else
|
else
|
||||||
value
|
value
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ require "strscan"
|
|||||||
# metatag = metatag_name ":" quoted_string
|
# metatag = metatag_name ":" quoted_string
|
||||||
# metatag_name = "user" | "fav" | "pool" | "order" | ...
|
# metatag_name = "user" | "fav" | "pool" | "order" | ...
|
||||||
# quoted_string = '"' /[^"]+/ '"'
|
# quoted_string = '"' /[^"]+/ '"'
|
||||||
|
# | "'" /[^']+/ "'"
|
||||||
# tag = /[^ *]+/
|
# tag = /[^ *]+/
|
||||||
# wildcard = /[^ ]+/
|
# wildcard = /[^ ]+/
|
||||||
#
|
#
|
||||||
@@ -172,6 +173,10 @@ class PostQuery
|
|||||||
a = accept(/([^"\\]|\\")*/).gsub(/\\"/, '"') # handle backslash escaped quotes
|
a = accept(/([^"\\]|\\")*/).gsub(/\\"/, '"') # handle backslash escaped quotes
|
||||||
expect('"')
|
expect('"')
|
||||||
a
|
a
|
||||||
|
elsif accept("'")
|
||||||
|
a = accept(/([^'\\]|\\')*/).gsub(/\\'/, "'") # handle backslash escaped quotes
|
||||||
|
expect("'")
|
||||||
|
a
|
||||||
else
|
else
|
||||||
string(/[^ ]+/)
|
string(/[^ ]+/)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -70,6 +70,13 @@ class PostQueryParserTest < ActiveSupport::TestCase
|
|||||||
assert_parse_equals('source:"\""', 'source:"\""')
|
assert_parse_equals('source:"\""', 'source:"\""')
|
||||||
assert_parse_equals(%q{source:"don't say \"lazy\" okay"}, %q{source:"don't say \"lazy\" okay"})
|
assert_parse_equals(%q{source:"don't say \"lazy\" okay"}, %q{source:"don't say \"lazy\" okay"})
|
||||||
assert_parse_equals(%q{(and source:foo)bar a)}, %q{(a (source:"foo)bar"))})
|
assert_parse_equals(%q{(and source:foo)bar a)}, %q{(a (source:"foo)bar"))})
|
||||||
|
|
||||||
|
assert_parse_equals('source:"foo bar"', "source:'foo bar'")
|
||||||
|
assert_parse_equals("source:foobar'(", "source:foobar'(")
|
||||||
|
assert_parse_equals('source:""', "source:''")
|
||||||
|
assert_parse_equals('source:"\'"', "source:'\\''")
|
||||||
|
assert_parse_equals(%q{source:"don't say \"lazy\" okay"}, %q{source:'don\'t say "lazy" okay'})
|
||||||
|
assert_parse_equals(%q{(and source:foo)bar a)}, %q{(a (source:'foo)bar'))})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "parse wildcard tags correctly" do
|
should "parse wildcard tags correctly" do
|
||||||
|
|||||||
Reference in New Issue
Block a user