chiark / gitweb /
prefer to use ids to names; names aren't even valid in divs
[ypp-sc-tools.db-live.git] / yarrg / web / routetextstring
index 0e4ae6eaf2b37d5786c05800ab1497dd7d1c6302..4202ce9a4881b69c2343ca00400f52105d926d2b 100644 (file)
@@ -6,6 +6,10 @@ $string
 </%args>
 <%perl>
 
+# typical url for this script:
+#  http://www.chiark.greenend.org.uk/ucgi/~clareb/mason/pirates/routetextstring?format=json&ocean=Midnight&string=d
+
+
 use CommodsWeb;
 use HTML::Entities;
 use JSON;
@@ -25,11 +29,12 @@ if ($format =~ 'json') {
        $r->content_type($ctype or $format);
        $output= sub { print to_json({
                success => 1,
-               show => encode_entities($canontext),
+               show => length $canontext ? encode_entities($canontext)
+                       : '&nbsp;',
        })};
        $output_wrong= sub { print to_json({
                success => 0,
-               show => encode_entities($_[0]),
+               show => $_[0],
        })};
 }              
 
@@ -47,7 +52,7 @@ foreach my $each (split m#[/|,]#, $string) {
        if (!@$results) {
                $err->('no island or arch matches "%s"');
        } elsif (@$results > 3) {
-               $err->('');
+               $err->('&nbsp;');
        } elsif (@$results > 1) {
                my @m= map { $_->[2] } @$results;
                $err->('ambiguous island or arch "%s", could be '.
@@ -56,7 +61,7 @@ foreach my $each (split m#[/|,]#, $string) {
        push @results, $results->[0];
 }
 
-$canontext= join ' | ', map { encode_entities($_->[2]) } @results;
+$canontext= join ' | ', map { $_->[2] } @results;
 
 $output->();