From 95214cc055fb602414243aa298b4736dbff0fec8 Mon Sep 17 00:00:00 2001 From: PJ Hampton Date: Mon, 11 Sep 2017 20:57:42 +0100 Subject: [PATCH] Calculator: Divide bug (#4483) * Add edge case. * Fix rouge regex. --- lib/DDG/Goodie/Calculator.pm | 3 ++- t/Calculator.t | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/DDG/Goodie/Calculator.pm b/lib/DDG/Goodie/Calculator.pm index cc605f48b..2fdd9c371 100644 --- a/lib/DDG/Goodie/Calculator.pm +++ b/lib/DDG/Goodie/Calculator.pm @@ -198,6 +198,7 @@ handle query => sub { return if $query =~ m#^\d{1,2}/\d{1,2}/\d{2,4}$#; return if $query =~ m#^0\d+/\d+$#; + # some shallow preprocessing of the query $query =~ s/^(?:what is|calculat(e|or)|solve|math)//i; $query =~ s/\s//g; @@ -216,7 +217,7 @@ handle query => sub { return if $query =~ m/0x[A-Za-z]{2,}/; return if $query =~ m/X\d+/; return if $query =~ m/\d+e\+\d+/; - return if $query =~ m{(?:7|9)/11}; # date edge case, US supermarket + return if $query =~ m{^(?:7|9)/11$}; # date edge case, US supermarket return if $query =~ m/.+=.+/; # check there isn't something on both sides of the equals sign return if $query =~ /^(?:minus|-|\+)\d+$/; diff --git a/t/Calculator.t b/t/Calculator.t index 7ccf4ba4a..c49372ade 100644 --- a/t/Calculator.t +++ b/t/Calculator.t @@ -434,6 +434,9 @@ ddg_goodie_test( '2 + cube 66 + 2' => build_test( '2 + cube(66) + 2' ), + '16739317 / 11147731' => build_test( + '16739317 / 11147731' + ), 'e2e4' => undef, 'cosh(4+-)' => undef,