Skip to content

Commit

Permalink
Ensure we do not swallow spaces inside quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
eric committed Jul 26, 2011
1 parent 4f3376a commit ae27bd0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1 +1,4 @@
pkg
.bundle
Gemfile.lock
.DS_Store
5 changes: 5 additions & 0 deletions Gemfile
@@ -1,3 +1,8 @@
source "http://rubygems.org"

gemspec

platform :mri_18 do
gem 'activesupport', '~> 2.3.5'
gem 'oniguruma'
end
4 changes: 2 additions & 2 deletions lib/textquery/textquery_grammar.treetop
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion spec/textquery_spec.rb
Expand Up @@ -14,7 +14,7 @@
#

describe TextQuery do
before(:all) do
before(:each) do
@parser = TextQuery.new
end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.