Permalink
Browse files

Ensure we do not swallow spaces inside quoted strings

  • Loading branch information...
1 parent 4f3376a commit ae27bd0c508ed8a2757b94f7494b681d435971a0 @eric eric committed Jul 26, 2011
Showing with 21 additions and 3 deletions.
  1. +3 −0 .gitignore
  2. +5 −0 Gemfile
  3. +2 −2 lib/textquery/textquery_grammar.treetop
  4. +11 −1 spec/textquery_spec.rb
View
3 .gitignore
@@ -1 +1,4 @@
pkg
+.bundle
+Gemfile.lock
+.DS_Store
View
5 Gemfile
@@ -1,3 +1,8 @@
source "http://rubygems.org"
gemspec
+
+platform :mri_18 do
+ gem 'activesupport', '~> 2.3.5'
+ gem 'oniguruma'
+end
View
4 lib/textquery/textquery_grammar.treetop
@@ -105,7 +105,7 @@ grammar TextQueryGrammar
end
}
/
- double_quote space double_quote_words space double_quote {
+ double_quote double_quote_words double_quote {
def eval(text, opt)
double_quote_words.eval(text, opt)
end
@@ -115,7 +115,7 @@ grammar TextQueryGrammar
end
}
/
- single_quote space single_quote_words space single_quote {
+ single_quote single_quote_words single_quote {
def eval(text, opt)
single_quote_words.eval(text, opt)
end
View
12 spec/textquery_spec.rb
@@ -14,7 +14,7 @@
#
describe TextQuery do
- before(:all) do
+ before(:each) do
@parser = TextQuery.new
end
@@ -136,6 +136,11 @@ def parse(input)
parse('"to be" OR NOT "to be"').eval("to be").should be_true
end
+ it "should not swallow spaces inside quoted strings" do
+ parse('" some text "').eval("this is some text", :delim => '').should be_false
+ parse('" some text "').eval("this is some text that should match", :delim => '').should be_true
+ end
+
it "should accept unbalanced quotes" do
parse("awesome").eval("M&M's are awesome").should be_true
parse("M&M's").eval("M&M's are awesome").should be_true
@@ -270,5 +275,10 @@ def parse(input)
TextQuery.new("a b").accept { |*a| a }.should == [ :and, [ :value, 'a' ], [ :value, 'b' ] ]
TextQuery.new("a OR b").accept { |*a| a }.should == [ :or, [ :value, 'a' ], [ :value, 'b' ] ]
end
+
+ it 'should not swallow spaces in quoted strings when traversed' do
+ TextQuery.new('" a "').accept { |*a| a }.should == [ :value, ' a ' ]
+
+ end
end
end

0 comments on commit ae27bd0

Please sign in to comment.