From: b Date: Sun, 25 Sep 2022 10:27:48 +0000 (+0000) Subject: added html entity encoding, X-Git-Tag: v1.0.0~1 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=c9d714f574b7b0d68c8eb7f86f445f893a56514d;p=botm%2Fconfig added html entity encoding, fixed whitespace handling for empty pattern --- diff --git a/configure.pl b/configure.pl index 3a13a61..d575160 100755 --- a/configure.pl +++ b/configure.pl @@ -271,6 +271,10 @@ # $0 - the text to be encoded # $1 - the regexp which specifies which characters should be encoded # if not specified then a default regexp is used +# @_HT_ENCODE is a function which will perform HTML entity encoding +# $0 - the text to be encoded +# $1 - the regexp which specifies which characters should be encoded +# if not specified then a default regexp is used # @_SPRINTF is a call to the Perl sprintf() function # $0 - the format string # $1 and continuing - the parameters to sprintf() @@ -372,6 +376,7 @@ use constant PATH_SEPARATOR => '_PATH_SEPARATOR'; use constant ESCAPE => '_ESCAPE'; use constant URL_ENCODE => '_URL_ENCODE'; +use constant HT_ENCODE => '_HT_ENCODE'; use constant PATH => '_PATH'; use constant SPRINTF => '_SPRINTF'; @@ -562,6 +567,7 @@ sub escape { return $outcome; } +# NOT UNICODE AWARE sub urlencode { (my $text, my $match) = @_; unless (defined $match) { @@ -580,6 +586,26 @@ sub urlencode { return $outcome; } +# NOT UNICODE AWARE +# (but there no real need to escaping non-ascii characters) +sub entityencode { + (my $text, my $match) = @_; + unless (defined $match) { + $match = '[\"=><\&]' + } + + my $outcome = ''; + foreach my $ch (split('', $text)) { + if ($ch =~ $match) { + $outcome .= sprintf('&#%02hu;',ord($ch)); + } + else { + $outcome .= $ch; + } + } + return $outcome; +} + sub join_path { (my $joiner, my @segments) = @_; @@ -790,6 +816,9 @@ sub parse_pattern { elsif ($name eq URL_ENCODE) { $return = urlencode(@parameter_list); } + elsif ($name eq HT_ENCODE) { + $return = entityencode(@parameter_list); + } elsif ($name eq PATH) { $return = join_path($cfg{PATH_SEPARATOR()},@parameter_list); } @@ -834,7 +863,7 @@ sub parse_value { if ($to_parse =~ /^((([^#\\])|(\\.))*)#/) { $to_parse = $1; } - if ($to_parse =~ /^[ \t]*([^ \t](.*[^ \t])?)[ \t]*$/) { + if ($to_parse =~ /^[ \t]*(([^ \t](.*[^ \t])?)?)[ \t]*$/) { $to_parse = $1; }