Skip to content

Commit

Permalink
[BUGFIX] Empty input should always be a potential match
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Sep 29, 2013
1 parent ff6265d commit ea6ef22
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/ruby_speech/ruby_speech.c
Expand Up @@ -82,7 +82,7 @@ static VALUE method_find_match(VALUE self, VALUE buffer)
}
return rb_funcall(self, rb_intern("match_for_buffer"), 1, buffer);
}
if (result == PCRE_ERROR_PARTIAL) {
if (result == PCRE_ERROR_PARTIAL || (int)strlen(input) == 0) {
VALUE PotentialMatch = rb_const_get(GRXML, rb_intern("PotentialMatch"));
return rb_class_new_instance(0, NULL, PotentialMatch);
}
Expand Down
3 changes: 2 additions & 1 deletion spec/ruby_speech/grxml/builtins_spec.rb
Expand Up @@ -145,7 +145,8 @@
it { should match('0123*456').and_interpret_as('dtmf-0 dtmf-1 dtmf-2 dtmf-3 dtmf-star dtmf-4 dtmf-5 dtmf-6') }
it { should match('0123*456*789').and_interpret_as('dtmf-0 dtmf-1 dtmf-2 dtmf-3 dtmf-star dtmf-4 dtmf-5 dtmf-6 dtmf-star dtmf-7 dtmf-8 dtmf-9') }

it { should not_match('') }
it { should potentially_match('') }

it { should not_match('#') }
end

Expand Down
4 changes: 4 additions & 0 deletions spec/ruby_speech/grxml/matcher_spec.rb
Expand Up @@ -27,6 +27,10 @@ module GRXML
input.should == '6'
end

it "should potentially match an empty buffer" do
subject.match('').should == GRXML::PotentialMatch.new
end

%w{1 2 3 4 5 7 8 9 10 66 26 61}.each do |input|
it "should not match '#{input}'" do
subject.match(input).should == GRXML::NoMatch.new
Expand Down

0 comments on commit ea6ef22

Please sign in to comment.