diff --git a/bibcop.pl b/bibcop.pl index 791a518..523b1de 100755 --- a/bibcop.pl +++ b/bibcop.pl @@ -355,8 +355,14 @@ sub check_year { my (%entry) = @_; if (exists $entry{'year'}) { my $year = $entry{'year'}; - if (not $year =~ /^[0-9]{3,4}$/) { - return "The format of the 'year' is wrong" + if ($year =~ /^\{.+\}$/) { + return; + } + if (not $year =~ /^[0-9]+$/) { + return "The format of the 'year' is wrong, may only contain numbers or must be wrapped in curly braces" + } + if (not $year =~ /^[0-9]{4}$/) { + return "Exactly four digits must be present in the 'year', or it must be wrapped in curly braces" } } } diff --git a/perl-tests/checks.pl b/perl-tests/checks.pl index 7ca44fe..cdcd076 100644 --- a/perl-tests/checks.pl +++ b/perl-tests/checks.pl @@ -95,6 +95,14 @@ package bibcop; check_passes($f, ('title' => 'Data Flow Languages and Architecture')); check_passes($f, ('title' => 'A Preliminary Architecture for a Basic Data-Flow Processor')); +$f = 'check_year'; +check_fails($f, ('year' => 'hello')); +check_fails($f, ('year' => '20019')); +check_fails($f, ('year' => '2009-2011')); +check_passes($f, ('year' => '{400 BC}')); +check_passes($f, ('year' => '2022')); +check_passes($f, ('year' => '1612')); + $f = 'check_pages'; check_fails($f, ('pages' => '1a')); check_fails($f, ('pages' => '40A'));