cleanup
- accented_chars changes for the future - substitutions in the Encode Goodie are now after the ‘else’ block - regex change to one liners - testsmaster
parent
34d4ad5f01
commit
38ec92a4a8
|
@ -31,9 +31,9 @@ sub append_css {
|
||||||
};
|
};
|
||||||
|
|
||||||
handle remainder => sub {
|
handle remainder => sub {
|
||||||
$_ =~ s/^\s*//g; # remove front whitespace
|
$_ =~ s/^\s+|\s+$//g; # remove front and back whitespace
|
||||||
$_ =~ s/^(for|of)\s+//g; # remove filler words at the start
|
$_ =~ s/^(for|of)\s+//g; # remove filler words at the start
|
||||||
$_ =~ s/\s*$//g; # remove back whitespace
|
$_ =~ s/^\s+|\s+$//g; # remove front and back whitespace that existed in between that may show up after removing the filler words
|
||||||
return unless ((/^(&?#(?:[0-9]+(?!_))+;?)$/) || (/^(&(?:[a-zA-Z]+(?!_))+;?)$/) || (/^(&?#[xX](?:[0-9A-Fa-f]+(?!_))+;?)$/)); # decimal (') || text with no underscores (¢) || hex (')
|
return unless ((/^(&?#(?:[0-9]+(?!_))+;?)$/) || (/^(&(?:[a-zA-Z]+(?!_))+;?)$/) || (/^(&?#[xX](?:[0-9A-Fa-f]+(?!_))+;?)$/)); # decimal (') || text with no underscores (¢) || hex (')
|
||||||
# "&" optional for all
|
# "&" optional for all
|
||||||
# ";" optional except in text type
|
# ";" optional except in text type
|
||||||
|
|
|
@ -256,39 +256,36 @@ attribution web => ["http://nishanths.github.io", "Nishanth Shanmugham"
|
||||||
handle remainder => sub {
|
handle remainder => sub {
|
||||||
|
|
||||||
# General query cleanup
|
# General query cleanup
|
||||||
$_ =~ s/^\s*//g; # remove front whitespace
|
$_ =~ s/^\s+|\s+$//g; # remove front and back whitespace
|
||||||
$_ =~ s/\s*$//g; # remove back whitespace
|
|
||||||
$_ =~ s/^(for|of)\s+//g; # remove filler words at the start (note: this will remove 'for' in "for euro sign", but not 'for' in "formula sign")
|
$_ =~ s/^(for|of)\s+//g; # remove filler words at the start (note: this will remove 'for' in "for euro sign", but not 'for' in "formula sign")
|
||||||
$_ =~ s/(symbol|sign)//g; # remove 'symbol' and 'sign'
|
$_ =~ s/(symbol|sign)//g; # remove 'symbol' and 'sign'
|
||||||
$_ =~ s/^\s*//g; # remove front whitespace again that may show up after removing the words above
|
$_ =~ s/^\s+|\s+$//g; # remove front and back whitespace that existed in between that may show up after removing the words above
|
||||||
$_ =~ s/\s*$//g; # remove back whitespace again that may show up after removing the words above
|
|
||||||
|
|
||||||
# Hash-specific query cleanup for better hits
|
# Hash-specific query cleanup for better hits
|
||||||
my $hashes_query = $_;
|
my $hashes_query = $_;
|
||||||
$hashes_query =~ s/\-/ /g; # change '-' to ' '
|
$hashes_query =~ s/\-/ /g; # change '-' to ' '
|
||||||
$hashes_query =~ s/"//g; # remove double quote
|
$hashes_query =~ s/"|'//g; # remove double and single quotes
|
||||||
$hashes_query =~ s/'//g; # remove single quote
|
|
||||||
|
|
||||||
# Hashes lookup
|
# Hashes lookup
|
||||||
if ($hashes_query) {
|
if ($hashes_query) {
|
||||||
my $key;
|
my $key;
|
||||||
my $value;
|
my $value;
|
||||||
# Query is for accented character
|
# Query is for accented character
|
||||||
if ($hashes_query =~ /^(a|A|e|E|i|I|o|O|u|U)\s*(grave|acute)$/) {
|
if ($hashes_query =~ /^([a-zA-Z])\s*(grave|acute)$/i) {
|
||||||
$hashes_query =~ s/\s*//g; # remove in-between spaces
|
$hashes_query = $1 . lc $2; # $1's capitalization matters for accented characters lookup, lc $2 allows for more freedom in queries
|
||||||
$key = $hashes_query; # capitalization matters for accented characters lookup
|
$key = $hashes_query;
|
||||||
$value = $accented_chars{$key};
|
$value = $accented_chars{$key};
|
||||||
# Not an accented character -- lookup the $codes hash instead
|
# Not an accented character -- lookup the $codes hash instead
|
||||||
} else {
|
} else {
|
||||||
$key = lc $hashes_query;
|
$key = lc $hashes_query;
|
||||||
$value = $codes{$key};
|
$value = $codes{$key};
|
||||||
|
}
|
||||||
# Try again after substitutions if there is no hit
|
# Try again after substitutions if there is no hit
|
||||||
unless (defined $value) {
|
unless (defined $value) {
|
||||||
$key =~ s/brackets/bracket/g;
|
$key =~ s/brackets/bracket/g;
|
||||||
$key =~ s/quotes/quote/g;
|
$key =~ s/quotes/quote/g;
|
||||||
$value = $codes{$key};
|
$value = $codes{$key};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
# Make final answer
|
# Make final answer
|
||||||
if (defined $value) {
|
if (defined $value) {
|
||||||
my $text = make_text($value);
|
my $text = make_text($value);
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
.zci--answer .zci--htmlentitiesencode {
|
.zci--answer .zci--htmlentitiesencode {
|
||||||
padding-top: 0.25em;
|
padding-top: 0.25em;
|
||||||
padding-bottom: 0.25em;
|
padding-bottom: 0.25em;
|
||||||
}
|
|
||||||
.zci--answer .zci--htmlentitiesencode .line-single {
|
|
||||||
font-weight: 300;
|
|
||||||
font-size: 1.5em;
|
|
||||||
}
|
|
||||||
.zci--answer .zci--htmlentitiesencode .line-multiple {
|
|
||||||
font-weight: 300;
|
font-weight: 300;
|
||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ ddg_goodie_test(
|
||||||
'html entity A-acute' => test_zci("Encoded HTML Entity: Á",html => qr/Aacute/),
|
'html entity A-acute' => test_zci("Encoded HTML Entity: Á",html => qr/Aacute/),
|
||||||
|
|
||||||
# Variety in querying accented chars #2
|
# Variety in querying accented chars #2
|
||||||
'html entity for E grave' => test_zci("Encoded HTML Entity: È", html => qr/Egrave/),
|
'html entity for E Grave' => test_zci("Encoded HTML Entity: È", html => qr/Egrave/),
|
||||||
|
|
||||||
# Query is a single typed-in character to encode
|
# Query is a single typed-in character to encode
|
||||||
'html escape &' => test_zci("Encoded HTML Entity: &", html => qr/amp/),
|
'html escape &' => test_zci("Encoded HTML Entity: &", html => qr/amp/),
|
||||||
|
|
|
@ -35,6 +35,9 @@ ddg_goodie_test(
|
||||||
|
|
||||||
'www.heroku.com/{rawwr!@#$%^&*()+=__} escapeurl' => test_zci("Percent-encoded URL: www.heroku.com%2F%7Brawwr!%40%23%24%25%5E%26*()%2B%3D__%7D",
|
'www.heroku.com/{rawwr!@#$%^&*()+=__} escapeurl' => test_zci("Percent-encoded URL: www.heroku.com%2F%7Brawwr!%40%23%24%25%5E%26*()%2B%3D__%7D",
|
||||||
html => qr/www.heroku.com%2F\%7Brawwr\!%40%23%24%25%5E%26\*\(\)%2B%3D__\%7D/),
|
html => qr/www.heroku.com%2F\%7Brawwr\!%40%23%24%25%5E%26\*\(\)%2B%3D__\%7D/),
|
||||||
|
|
||||||
|
'hello there escapeurl' => test_zci("Percent-encoded URL: hello%20there",
|
||||||
|
html => qr/hello%20there/),
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in New Issue