Skip to content
This repository was archived by the owner on Oct 15, 2022. It is now read-only.

Commit 6244a1a

Browse files
committed
Add stricter filters on year
1 parent 9139b9d commit 6244a1a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/DDG/Goodie/ChineseZodiac.pm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ handle remainder => sub {
4848
$year_gregorian = DateTime->now(time_zone => 'Asia/Shanghai')->subtract(years => 1) or return;
4949

5050
#If no relative year was supplied, look for an explicit year
51-
# DateTime::Event::SolarTerm only supports 1900--2069
52-
} elsif (/\b(\d{4})\b/) {
53-
return unless 1900 le $1 && $1 le 2069;
51+
# DateTime::Event::SolarTerm only supports 1900--2069, so
52+
# return nothing if the user provides a year outside this range
53+
} elsif (/\b(\d+)\b/) {
54+
return unless $1 >= 1900 && $1 <= 2069;
5455
$year_gregorian = DateTime->new(year => $1, month => 6, time_zone => 'Asia/Shanghai');
5556

5657
#Otherwise, default to now if it seems like the user is

t/ChineseZodiac.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ ddg_goodie_test(
6767
'chinese zodiac 1900' => test_zci('Rat', html => qr/Rat/),
6868
'chinese zodiac 2069' => test_zci('Ox', html => qr/Ox/),
6969
'chinese zodiac 2070' => undef,
70+
'chinese zodiac 2000000000000' => undef,
7071

7172
);
7273

0 commit comments

Comments
 (0)