chiark / gitweb /
Properly quote various error messages
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 31 Oct 2009 19:09:50 +0000 (19:09 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 31 Oct 2009 19:09:50 +0000 (19:09 +0000)
yarrg/CommodsWeb.pm
yarrg/web/check_capacitystring
yarrg/web/check_capitalstring
yarrg/web/check_commodstring
yarrg/web/check_distance
yarrg/web/check_islandstring
yarrg/web/check_lossperleague
yarrg/web/check_routestring
yarrg/web/qtextstringcheck
yarrg/web/query_age

index ab2a4a3..461a8ad 100644 (file)
@@ -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 '&#8220;'.CGI::escapeHTML($_[0]).'&#8221;';
+#    return '&#8216;'.CGI::escapeHTML($_[0]).'&#8217;';
+}
+
 package CommodsWeb::ExpectedError;
 
 sub emsg ($) {
index 52eab28..b958dff 100644 (file)
@@ -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;
index 53aceec..24617d7 100644 (file)
@@ -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);
index de7cda8..a6aa726 100644 (file)
@@ -45,11 +45,11 @@ SELECT commodname,commodid
 </%method>
 
 <%method nomatch>
-  no commodity matches "<% $ARGS{spec} |h %>"
+  no commodity matches <% $ARGS{specq} %>
 </%method>
 
 <%method ambiguous>
-  ambiguous commodity "<% $ARGS{spec} |h %>",
+  ambiguous commodity <% $ARGS{specq} %>,
   could be <% $ARGS{couldbe} |h %>
 </%method>
 
index 223cc5a..4d1a4e3 100644 (file)
@@ -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);
index e8664d5..bb33db1 100644 (file)
@@ -45,11 +45,11 @@ maxambig => 5
 </%method>
 
 <%method nomatch>
-  no island matches "<% $ARGS{spec} |h %>"
+  no island matches <% $ARGS{specq} %>
 </%method>
 
 <%method ambiguous>
-  ambiguous island "<% $ARGS{spec} |h %>",
+  ambiguous island <% $ARGS{specq} %>,
   could be <% $ARGS{couldbe} |h %>
 </%method>
 
index 9375355..a37382e 100644 (file)
@@ -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);
index cfa7ec7..6741eae 100644 (file)
@@ -47,11 +47,11 @@ UNION ALL   SELECT DISTINCT archipelago,NULL,archipelago
 </%method>
 
 <%method nomatch>
-  no island or arch matches "<% $ARGS{spec} |h %>"
+  no island or arch matches <% $ARGS{specq} %>
 </%method>
 
 <%method ambiguous>
-  ambiguous island or arch "<% $ARGS{spec} |h %>",
+  ambiguous island or arch <% $ARGS{specq} %>,
   could be <% $ARGS{couldbe} |h %>
 </%method>
 
index 9dce828..0a75f8e 100755 (executable)
@@ -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;
index fd2044d..efd7096 100644 (file)
@@ -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'};