From ad29b01fe6470a4b3bb108a8f485657927175e24 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 31 Oct 2009 19:09:50 +0000 Subject: [PATCH] Properly quote various error messages --- yarrg/CommodsWeb.pm | 7 ++++++- yarrg/web/check_capacitystring | 14 ++++++++------ yarrg/web/check_capitalstring | 2 +- yarrg/web/check_commodstring | 4 ++-- yarrg/web/check_distance | 2 +- yarrg/web/check_islandstring | 4 ++-- yarrg/web/check_lossperleague | 2 +- yarrg/web/check_routestring | 4 ++-- yarrg/web/qtextstringcheck | 7 ++++--- yarrg/web/query_age | 1 - 10 files changed, 27 insertions(+), 20 deletions(-) diff --git a/yarrg/CommodsWeb.pm b/yarrg/CommodsWeb.pm index ab2a4a3..461a8ad 100644 --- a/yarrg/CommodsWeb.pm +++ b/yarrg/CommodsWeb.pm @@ -52,7 +52,7 @@ BEGIN { &to_json_shim &to_json_protecttags &set_ctype_utf8 &webdatadir &expected_error &dbw_lookup_string - &printable &tr_datarow + &printable &tr_datarow &escerrq &prettyprint_age &meta_prettyprint_age); %EXPORT_TAGS = ( ); @@ -222,6 +222,11 @@ sub tr_datarow ($$) { } } +sub escerrq ($) { + return '“'.CGI::escapeHTML($_[0]).'”'; +# return '‘'.CGI::escapeHTML($_[0]).'’'; +} + package CommodsWeb::ExpectedError; sub emsg ($) { diff --git a/yarrg/web/check_capacitystring b/yarrg/web/check_capacitystring index 52eab28..b958dff 100644 --- a/yarrg/web/check_capacitystring +++ b/yarrg/web/check_capacitystring @@ -96,9 +96,9 @@ my $parse_values= sub { FROM commods WHERE commodname LIKE ?"); my ($emsg,$commod,@umv)= dbw_lookup_string($spec,$commodsth,1,0,0, - "No commodity or unit matches \`$spec'", - "Ambiguous commodity (or unit) \`$spec'", - undef); + "No commodity or unit matches ".escerrq($spec), + "Ambiguous commodity (or unit) ".escerrq($spec), + undef); expected_error($emsg) if defined $emsg; $debugf->("VALUE COMMOD FOUND '$commod' @umv"); foreach my $mvi (0,1) { @@ -109,7 +109,8 @@ my $parse_values= sub { push @canon, $commod; } else { s/\s+$//; - expected_error("Did not understand value \`$_'"); + expected_error("Did not understand value ". + escerrq($_)); } } }; @@ -131,14 +132,15 @@ my $parse_term= sub { push @canon, sprintf "%g%%", $pct; } elsif (!m/[^a-z]/i) { $debugf->("TERM NAME"); - expected_error("Name (should be unit or commodity) \`$_'". + expected_error("Name (should be unit or commodity)". + escerrq($_). " without preceding quantity") unless $first_term; my $sth= $dbh->prepare("SELECT name,mass,volume". " FROM vessels WHERE name LIKE ?"); my ($emsg,$ship,@smv)= dbw_lookup_string($_,$sth,1,1,2, - "Ship name `$_' not understood.", + "Ship name ".escerrq($_)." not understood.", "Too many matching ship types.", sub { "Ambiguous - could be $_[1]" }); expected_error($emsg) if defined $emsg; diff --git a/yarrg/web/check_capitalstring b/yarrg/web/check_capitalstring index 53aceec..24617d7 100644 --- a/yarrg/web/check_capitalstring +++ b/yarrg/web/check_capitalstring @@ -53,7 +53,7 @@ if (!m/\S/) { $capital= $1; $canon= "$capital PoE"; } else { - expected_error("Cannot understand capital \`$_'."); + expected_error("Cannot understand capital ".escerrq($_)."."); } return ($canon,$capital); diff --git a/yarrg/web/check_commodstring b/yarrg/web/check_commodstring index de7cda8..a6aa726 100644 --- a/yarrg/web/check_commodstring +++ b/yarrg/web/check_commodstring @@ -45,11 +45,11 @@ SELECT commodname,commodid <%method nomatch> - no commodity matches "<% $ARGS{spec} |h %>" + no commodity matches <% $ARGS{specq} %> <%method ambiguous> - ambiguous commodity "<% $ARGS{spec} |h %>", + ambiguous commodity <% $ARGS{specq} %>, could be <% $ARGS{couldbe} |h %> diff --git a/yarrg/web/check_distance b/yarrg/web/check_distance index 223cc5a..4d1a4e3 100644 --- a/yarrg/web/check_distance +++ b/yarrg/web/check_distance @@ -59,7 +59,7 @@ if (!m/\S/) { $leagues= $1; $canon= "$leagues leagues"; } else { - expected_error("Cannot understand distance \`$_'."); + expected_error("Cannot understand distance ".escerrq($_)."."); } return ($canon,$leagues); diff --git a/yarrg/web/check_islandstring b/yarrg/web/check_islandstring index e8664d5..bb33db1 100644 --- a/yarrg/web/check_islandstring +++ b/yarrg/web/check_islandstring @@ -45,11 +45,11 @@ maxambig => 5 <%method nomatch> - no island matches "<% $ARGS{spec} |h %>" + no island matches <% $ARGS{specq} %> <%method ambiguous> - ambiguous island "<% $ARGS{spec} |h %>", + ambiguous island <% $ARGS{specq} %>, could be <% $ARGS{couldbe} |h %> diff --git a/yarrg/web/check_lossperleague b/yarrg/web/check_lossperleague index 9375355..a37382e 100644 --- a/yarrg/web/check_lossperleague +++ b/yarrg/web/check_lossperleague @@ -54,7 +54,7 @@ if (!m/\S/) { $pct= 100.0/$1; $str= sprintf("1/%d", $1); } else { - expected_error("Cannot understand loss per league \`$_'."); + expected_error("Cannot understand loss per league ".escerrq($_)."."); } return ("$str per league", $pct); diff --git a/yarrg/web/check_routestring b/yarrg/web/check_routestring index cfa7ec7..6741eae 100644 --- a/yarrg/web/check_routestring +++ b/yarrg/web/check_routestring @@ -47,11 +47,11 @@ UNION ALL SELECT DISTINCT archipelago,NULL,archipelago <%method nomatch> - no island or arch matches "<% $ARGS{spec} |h %>" + no island or arch matches <% $ARGS{specq} %> <%method ambiguous> - ambiguous island or arch "<% $ARGS{spec} |h %>", + ambiguous island or arch <% $ARGS{specq} %>, could be <% $ARGS{couldbe} |h %> diff --git a/yarrg/web/qtextstringcheck b/yarrg/web/qtextstringcheck index 9dce828..0a75f8e 100755 --- a/yarrg/web/qtextstringcheck +++ b/yarrg/web/qtextstringcheck @@ -65,7 +65,7 @@ my $mydbh; $dbh ||= ($mydbh= dbw_connect($ocean)); my $debugf= !$debug ? sub { } : sub { - print "@_\n"; + print escapeHTML("@_")."\n"; }; $debugf->("QTSC STRING '$string'"); @@ -105,11 +105,12 @@ if ($chk->method_exists('execute')) { $sth, $sqlstmt_nqs, $chk->attr_exists('abbrev_initials'), $chk->attr('maxambig'), - $chk->scall_method("nomatch", spec => $each), + $chk->scall_method("nomatch", specq => escerrq($each)), $chk->scall_method("manyambig"), sub { $chk->scall_method("ambiguous", - spec => $each, couldbe => $_[1]) + specq => escerrq($each), + couldbe => $_[1]) }); if (defined $temsg) { $emsg= $temsg; diff --git a/yarrg/web/query_age b/yarrg/web/query_age index fd2044d..efd7096 100644 --- a/yarrg/web/query_age +++ b/yarrg/web/query_age @@ -81,7 +81,6 @@ $sth->execute(); % $da_ages{'id_loaded'}= 0; % my $rowix= 0; % while ($row= $fetchrow->()) { -% print STDERR "$row\n"; % my $rowid= "id_$row->{'islandid'}"; % my $cellid= "c$rowid"; % my $age= $now - $row->{'timestamp'}; -- 2.30.2