Switch encode_entities() to html_enc()
This is pretty much a straight one-for-one swap with some minor goodness in the form of the already wrapped up array handling in one case. I did not do any refactoring of the code although some places looked like they could use it. Addresses issue #591.master
parent
52f0a1aec3
commit
89d34ba766
|
@ -3,7 +3,6 @@ package DDG::Goodie::Anagram;
|
||||||
|
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
use List::Util 'shuffle';
|
use List::Util 'shuffle';
|
||||||
use HTML::Entities qw(encode_entities);
|
|
||||||
|
|
||||||
triggers start => "anagram", "anagrams";
|
triggers start => "anagram", "anagrams";
|
||||||
|
|
||||||
|
@ -122,15 +121,15 @@ handle remainder => sub {
|
||||||
my @chars = shuffle split (//, $word);
|
my @chars = shuffle split (//, $word);
|
||||||
$w = join '', @chars;
|
$w = join '', @chars;
|
||||||
} while ($w eq $word);
|
} while ($w eq $word);
|
||||||
return $word, html => html_output ('Sorry, we found no anagrams for "'.encode_entities ($word).'". We scrambled it for you:', $w);
|
return $word, html => html_output('Sorry, we found no anagrams for "'.html_enc($word).'". We scrambled it for you:', $w);
|
||||||
}
|
}
|
||||||
|
|
||||||
my $response = join ', ', @output;
|
my $response = join ', ', @output;
|
||||||
my $output_str = 'Anagrams of '.encode_entities ($word).'"';
|
my $output_str = 'Anagrams of '.html_enc($word).'"';
|
||||||
unless ($full_word) {
|
unless ($full_word) {
|
||||||
$output_str .= " of length $len";
|
$output_str .= " of length $len";
|
||||||
}
|
}
|
||||||
return $response, html => html_output ($output_str, $response);
|
return $response, html => html_output($output_str, $response);
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -6,8 +6,6 @@ use warnings;
|
||||||
|
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
|
|
||||||
use HTML::Entities;
|
|
||||||
|
|
||||||
triggers startend => 'bash if', 'bash';
|
triggers startend => 'bash if', 'bash';
|
||||||
primary_example_queries 'bash [ -z hello ]';
|
primary_example_queries 'bash [ -z hello ]';
|
||||||
secondary_example_queries 'bash if [[ "abc" -lt "cba" ]]';
|
secondary_example_queries 'bash if [[ "abc" -lt "cba" ]]';
|
||||||
|
@ -87,11 +85,11 @@ handle remainder => sub {
|
||||||
my $text_output = $if_description{$op};
|
my $text_output = $if_description{$op};
|
||||||
$text_output =~ s/^true/false/ if $not;
|
$text_output =~ s/^true/false/ if $not;
|
||||||
|
|
||||||
my $html_output = encode_entities($text_output);
|
my $html_output = html_enc($text_output);
|
||||||
my $html_right_arg = encode_entities($right_arg);
|
my $html_right_arg = html_enc($right_arg);
|
||||||
|
|
||||||
if ($left_arg) {
|
if ($left_arg) {
|
||||||
my $html_left_arg = encode_entities($left_arg);
|
my $html_left_arg = html_enc($left_arg);
|
||||||
$text_output =~ s/ARG1/$left_arg/g;
|
$text_output =~ s/ARG1/$left_arg/g;
|
||||||
$html_output =~ s/ARG1/<pre>$html_left_arg<\/pre>/g;
|
$html_output =~ s/ARG1/<pre>$html_left_arg<\/pre>/g;
|
||||||
}
|
}
|
||||||
|
@ -99,8 +97,8 @@ handle remainder => sub {
|
||||||
$text_output =~ s/ARG2/$right_arg/g;
|
$text_output =~ s/ARG2/$right_arg/g;
|
||||||
$html_output =~ s/ARG2/<pre>$html_right_arg<\/pre>/g;
|
$html_output =~ s/ARG2/<pre>$html_right_arg<\/pre>/g;
|
||||||
|
|
||||||
my $intro = "The Bash expression <pre>" . encode_entities($_) . "</pre> results to";
|
my $intro = "The Bash expression <pre>" . html_enc($_) . "</pre> results to";
|
||||||
return "$intro $text_output.", html => append_css("$intro $html_output."), heading => encode_entities($_) . " (Bash)";
|
return "$intro $text_output.", html => append_css("$intro $html_output."), heading => html_enc($_) . " (Bash)";
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -4,7 +4,6 @@ package DDG::Goodie::Conversions;
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
with 'DDG::GoodieRole::NumberStyler';
|
with 'DDG::GoodieRole::NumberStyler';
|
||||||
|
|
||||||
use HTML::Entities;
|
|
||||||
use Math::Round qw/nearest/;
|
use Math::Round qw/nearest/;
|
||||||
use bignum;
|
use bignum;
|
||||||
use Convert::Pluggable;
|
use Convert::Pluggable;
|
||||||
|
@ -68,8 +67,8 @@ sub append_css {
|
||||||
|
|
||||||
sub wrap_html {
|
sub wrap_html {
|
||||||
my ($factor, $result, $styler) = @_;
|
my ($factor, $result, $styler) = @_;
|
||||||
my $from = $styler->with_html($factor) . " <span class='text--secondary'>" . encode_entities($result->{'from_unit'}) . "</span>";
|
my $from = $styler->with_html($factor) . " <span class='text--secondary'>" . html_enc($result->{'from_unit'}) . "</span>";
|
||||||
my $to = $styler->with_html($result->{'result'}) . " <span class='text--secondary'>" . encode_entities($result->{'to_unit'}) . "</span>";
|
my $to = $styler->with_html($result->{'result'}) . " <span class='text--secondary'>" . html_enc($result->{'to_unit'}) . "</span>";
|
||||||
return append_css("<div class='zci--conversions text--primary'>$from = $to</div>");
|
return append_css("<div class='zci--conversions text--primary'>$from = $to</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ package DDG::Goodie::ConvertLatLon;
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
use utf8;
|
use utf8;
|
||||||
use Geo::Coordinates::DecimalDegrees;
|
use Geo::Coordinates::DecimalDegrees;
|
||||||
use HTML::Entities;
|
|
||||||
use Math::SigFigs qw(:all);
|
use Math::SigFigs qw(:all);
|
||||||
use Math::Round;
|
use Math::Round;
|
||||||
|
|
||||||
|
@ -280,8 +279,8 @@ sub wrap_html {
|
||||||
my @results = @{$_[1]};
|
my @results = @{$_[1]};
|
||||||
my $toFormat = $_[2];
|
my $toFormat = $_[2];
|
||||||
|
|
||||||
my $queries = join wrap_secondary(', '), map { encode_entities($_) } @queries;
|
my $queries = join wrap_secondary(', '), html_enc(@queries);
|
||||||
my $results = join wrap_secondary(', '), map { encode_entities($_) } @results;
|
my $results = join wrap_secondary(', '), html_enc(@results);
|
||||||
|
|
||||||
my $html = "<div class='zci--conversions text--primary'>" . $queries . wrap_secondary(' in ' . $toFormat . ': ') . $results . "</div>";
|
my $html = "<div class='zci--conversions text--primary'>" . $queries . wrap_secondary(' in ' . $toFormat . ': ') . $results . "</div>";
|
||||||
return append_css($html);
|
return append_css($html);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package DDG::Goodie::HTMLEntitiesEncode;
|
package DDG::Goodie::HTMLEntitiesEncode;
|
||||||
# ABSTRACT: Displays the HTML entity code for the query name.
|
# ABSTRACT: Displays the HTML entity code for the query name.
|
||||||
|
|
||||||
use HTML::Entities qw(encode_entities);
|
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
@ -301,16 +300,16 @@ handle remainder => sub {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Query maybe a single typed-in character to encode
|
# Query maybe a single typed-in character to encode
|
||||||
# No hits above if we got this far, use encode_entities() of HTML::Entities
|
# No hits above if we got this far, use html_enc()
|
||||||
if ( (/^(?:")(?<char>.)(?:")\s*\??$/) # a (captured) single character within double quotes
|
if ( (/^(?:")(?<char>.)(?:")\s*\??$/) # a (captured) single character within double quotes
|
||||||
|| (/^(?:'')(?<char>.)(?:'')\s*\??$/) # or within single quotes
|
|| (/^(?:'')(?<char>.)(?:'')\s*\??$/) # or within single quotes
|
||||||
|| (/^(?<char>.)\s*\??$/)) { # or stand-alone
|
|| (/^(?<char>.)\s*\??$/)) { # or stand-alone
|
||||||
my $entity = encode_entities($+{char});
|
my $entity = html_enc($+{char});
|
||||||
if ($entity eq $+{char}) { # encode_entities() was unsuccessful and returned the input itself
|
if ($entity eq $+{char}) { # html_enc() was unsuccessful and returned the input itself
|
||||||
$entity = ord($+{char}); # get the decimal
|
$entity = ord($+{char}); # get the decimal
|
||||||
$entity = '#' . $entity; # dress it up like a decimal
|
$entity = '#' . $entity; # dress it up like a decimal
|
||||||
}
|
}
|
||||||
# Remove '&' and ';' from the output of encode_entities(), these will be added in html
|
# Remove '&' and ';' from the output of html_enc(), these will be added in html
|
||||||
$entity =~ s/^&//g;
|
$entity =~ s/^&//g;
|
||||||
$entity =~ s/;$//g;
|
$entity =~ s/;$//g;
|
||||||
# Make final answer
|
# Make final answer
|
||||||
|
|
|
@ -3,7 +3,6 @@ package DDG::Goodie::IDN;
|
||||||
|
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
use Net::IDN::Encode ':all';
|
use Net::IDN::Encode ':all';
|
||||||
use HTML::Entities;
|
|
||||||
use utf8;
|
use utf8;
|
||||||
|
|
||||||
primary_example_queries 'idn exämple.com';
|
primary_example_queries 'idn exämple.com';
|
||||||
|
@ -31,10 +30,10 @@ handle query_lc => sub {
|
||||||
$idn = 'internationalized domain: ' if $1 eq 'internationalize domain';
|
$idn = 'internationalized domain: ' if $1 eq 'internationalize domain';
|
||||||
return unless m/\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|asia|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|local|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xxx|ye|yt|za|zm|zw)$/i;
|
return unless m/\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|asia|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|local|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xxx|ye|yt|za|zm|zw)$/i;
|
||||||
if(/^xn--/) {
|
if(/^xn--/) {
|
||||||
return 'Decoded ' . $idn . encode_entities(domain_to_unicode($_));
|
return 'Decoded ' . $idn . html_enc(domain_to_unicode($_));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 'Encoded ' . $idn . encode_entities(domain_to_ascii($_));
|
return 'Encoded ' . $idn . html_enc(domain_to_ascii($_));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,8 +3,6 @@ package DDG::Goodie::Lowercase;
|
||||||
|
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
|
|
||||||
use HTML::Entities;
|
|
||||||
|
|
||||||
name "Lowercase";
|
name "Lowercase";
|
||||||
description "Convert a string into lowercase.";
|
description "Convert a string into lowercase.";
|
||||||
primary_example_queries "lowercase GitHub";
|
primary_example_queries "lowercase GitHub";
|
||||||
|
@ -32,7 +30,7 @@ handle remainder => sub {
|
||||||
|
|
||||||
# Encode the variable before putting it in HTML.
|
# Encode the variable before putting it in HTML.
|
||||||
# There's no need to encode the $text variable because that gets encoded internally.
|
# There's no need to encode the $text variable because that gets encoded internally.
|
||||||
$lower = encode_entities($lower);
|
$lower = html_enc($lower);
|
||||||
|
|
||||||
my $html = qq(<div class="zci--lowercase"><span class="text--primary">$lower</span></div>);
|
my $html = qq(<div class="zci--lowercase"><span class="text--primary">$lower</span></div>);
|
||||||
$html = append_css($html);
|
$html = append_css($html);
|
||||||
|
|
|
@ -4,7 +4,6 @@ package DDG::Goodie::MD5;
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
use Digest::MD5 qw(md5_base64 md5_hex);
|
use Digest::MD5 qw(md5_base64 md5_hex);
|
||||||
use Encode qw(encode);
|
use Encode qw(encode);
|
||||||
use HTML::Entities qw(encode_entities);
|
|
||||||
|
|
||||||
zci answer_type => 'md5';
|
zci answer_type => 'md5';
|
||||||
zci is_cached => 1;
|
zci is_cached => 1;
|
||||||
|
@ -26,7 +25,7 @@ sub html_output {
|
||||||
my ($str, $md5) = @_;
|
my ($str, $md5) = @_;
|
||||||
|
|
||||||
# prevent XSS
|
# prevent XSS
|
||||||
$str = encode_entities($str);
|
$str = html_enc($str);
|
||||||
|
|
||||||
return "<style type='text/css'>$css</style>"
|
return "<style type='text/css'>$css</style>"
|
||||||
."<div class='zci--md5'>"
|
."<div class='zci--md5'>"
|
||||||
|
|
|
@ -4,7 +4,6 @@ package DDG::Goodie::RegexCheatSheet;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use HTML::Entities;
|
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
|
|
||||||
zci answer_type => "regex_cheat";
|
zci answer_type => "regex_cheat";
|
||||||
|
@ -216,7 +215,7 @@ handle remainder => sub {
|
||||||
# Let the user provide a number for the {n} pattern, e.g., {5} would say "Exactly 5 occurrences".
|
# Let the user provide a number for the {n} pattern, e.g., {5} would say "Exactly 5 occurrences".
|
||||||
elsif ($_ =~ /^\{([0-9]+)\}$/) {
|
elsif ($_ =~ /^\{([0-9]+)\}$/) {
|
||||||
return answer => "$_ - Exactly $1 occurrences",
|
return answer => "$_ - Exactly $1 occurrences",
|
||||||
html => "<code>" . encode_entities($_) . "</code> - Exactly " . encode_entities($_) . " occurrences",
|
html => "<code>" . html_enc($_) . "</code> - Exactly " . html_enc($_) . " occurrences",
|
||||||
heading => $heading;
|
heading => $heading;
|
||||||
}
|
}
|
||||||
# Let the user provide numbers for {n,} and {n,m}, e.g., {4,} would say "4 or more occurrences".
|
# Let the user provide numbers for {n,} and {n,m}, e.g., {4,} would say "4 or more occurrences".
|
||||||
|
@ -224,18 +223,18 @@ handle remainder => sub {
|
||||||
if ($2) {
|
if ($2) {
|
||||||
return unless ($1 < $2);
|
return unless ($1 < $2);
|
||||||
return answer => "$_ - Between $1 and $2 occurrences",
|
return answer => "$_ - Between $1 and $2 occurrences",
|
||||||
html => "<code>" . encode_entities($_) . "</code> - Between $1 and $2 occurrences",
|
html => "<code>" . html_enc($_) . "</code> - Between $1 and $2 occurrences",
|
||||||
heading => $heading;
|
heading => $heading;
|
||||||
}
|
}
|
||||||
return answer => "$_ - $1 or more",
|
return answer => "$_ - $1 or more",
|
||||||
html => "<code>" . encode_entities($_) . "</code> - $1 or more occurrences",
|
html => "<code>" . html_enc($_) . "</code> - $1 or more occurrences",
|
||||||
heading => $heading;
|
heading => $heading;
|
||||||
}
|
}
|
||||||
# Check our map if it's in our list of regex patterns.
|
# Check our map if it's in our list of regex patterns.
|
||||||
return unless $syntax_map{$syntax_key};
|
return unless $syntax_map{$syntax_key};
|
||||||
|
|
||||||
my $text_output = "$_ - $syntax_map{$syntax_key}";
|
my $text_output = "$_ - $syntax_map{$syntax_key}";
|
||||||
my $html_output = "<code>" . encode_entities($_) . "</code> - " . encode_entities($syntax_map{$syntax_key});
|
my $html_output = "<code>" . html_enc($_) . "</code> - " . html_enc($syntax_map{$syntax_key});
|
||||||
return answer => $text_output, html => $html_output, heading => $heading;
|
return answer => $text_output, html => $html_output, heading => $heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,9 +249,9 @@ handle remainder => sub {
|
||||||
sub add_table_data {
|
sub add_table_data {
|
||||||
my ($text, $is_code) = @_;
|
my ($text, $is_code) = @_;
|
||||||
if($is_code) {
|
if($is_code) {
|
||||||
return "<td><code>" . encode_entities($text) . "</code></td>";
|
return "<td><code>" . html_enc($text) . "</code></td>";
|
||||||
}
|
}
|
||||||
return "<td>" . encode_entities($text) . "</tb>";
|
return "<td>" . html_enc($text) . "</tb>";
|
||||||
}
|
}
|
||||||
|
|
||||||
for(my $column = 0; $column < scalar(@category_column); ++$column) {
|
for(my $column = 0; $column < scalar(@category_column); ++$column) {
|
||||||
|
|
|
@ -3,8 +3,6 @@ package DDG::Goodie::Uppercase;
|
||||||
|
|
||||||
use DDG::Goodie;
|
use DDG::Goodie;
|
||||||
|
|
||||||
use HTML::Entities;
|
|
||||||
|
|
||||||
triggers start => 'uppercase', 'upper case', 'allcaps', 'all caps', 'strtoupper', 'toupper';
|
triggers start => 'uppercase', 'upper case', 'allcaps', 'all caps', 'strtoupper', 'toupper';
|
||||||
# leaving out 'uc' because of queries like "UC Berkley", etc
|
# leaving out 'uc' because of queries like "UC Berkley", etc
|
||||||
# 2014-08-10: triggers to "start"-only to make it act more like a "command"
|
# 2014-08-10: triggers to "start"-only to make it act more like a "command"
|
||||||
|
@ -38,7 +36,7 @@ handle remainder => sub {
|
||||||
|
|
||||||
# Encode the variable before putting it in HTML.
|
# Encode the variable before putting it in HTML.
|
||||||
# There's no need to encode the $text variable because that gets encoded internally.
|
# There's no need to encode the $text variable because that gets encoded internally.
|
||||||
$upper = encode_entities($upper);
|
$upper = html_enc($upper);
|
||||||
|
|
||||||
my $html = qq(<div class="zci--uppercase"><span class="text--primary">$upper</span></div>);
|
my $html = qq(<div class="zci--uppercase"><span class="text--primary">$upper</span></div>);
|
||||||
$html = append_css($html);
|
$html = append_css($html);
|
||||||
|
|
Loading…
Reference in New Issue