Blacklist certain formats

The %{method} format is probably a bit too 'powerful', so we will not
return an answer if it is included.

We should allow blacklisted formats (as text only), but escape them so they don't
interfere with the actual formats.
master
Ben Moon 2016-04-13 09:48:28 +01:00
parent 941f03481e
commit 4b858eacaa
2 changed files with 13 additions and 3 deletions

View File

@ -34,12 +34,20 @@ my %standard_queries = (
'year' => ['%Y', 'Year'],
);
my @blacklist = (
'\\%{[^}]*}',
);
my $blacklist_re = join '|', map { "($_)" } @blacklist;
my $standard_re = join '|', map { "($_)" } (keys %standard_queries);
handle query => sub {
my $query = shift;
my $format;
my $type = 'format';
# TODO: Allow blacklisted elements, but escape them for formatting.
return if $query =~ /$blacklist_re/;
if ($query =~ /^random ($standard_re)$/i) {
my $standard_query = $1;
my $k = first { $standard_query =~ qr/^$_$/i } (keys %standard_queries);

View File

@ -70,9 +70,11 @@ ddg_goodie_test(
language_test('my', 'random time', 'Time', re($time_12_my), 1),
language_test('my', 'random day', 'Weekday', re($day_my), 1),
# Invalid Queries
'date for %K' => undef,
'random number' => undef,
'example date' => undef,
'date for %K' => undef,
'date for %{year}' => undef,
'date for %Y %{year}' => undef,
'random number' => undef,
'example date' => undef,
);
done_testing;