diff options
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 23 | ||||
-rw-r--r-- | templates/web/default/report/_main.html | 6 | ||||
-rw-r--r-- | templates/web/default/report/updates.html | 6 |
3 files changed, 11 insertions, 24 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 8f1aaa085..63aade4c9 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -5,6 +5,7 @@ use strict; use warnings; use mySociety::Locale; +use mySociety::Web qw(ent); use FixMyStreet; use CrossSell; @@ -17,7 +18,7 @@ __PACKAGE__->config( render_die => 1, expose_methods => [ 'loc', 'nget', 'tprintf', 'display_crosssell_advert', 'prettify_epoch', - 'split_into_lines', + 'add_links', ], ); @@ -106,27 +107,21 @@ sub prettify_epoch { return Page::prettify_epoch( $c->req, $epoch, $short_bool ); } -=head2 split_into_lines +=head2 add_links - [% FOREACH line IN split_into_lines( text ) %] - <p> - [% line | html %] - </p> - [% END %] + [% add_links( text ) | html_para %] -Split some text into an array of lines on double new lines. +Add some links to some text (and thus HTML-escapes the other text. =cut -sub split_into_lines { +sub add_links { my ( $self, $c, $text ) = @_; - my @lines; $text =~ s/\r//g; - - @lines = split /\n{2,}/, $text; - - return \@lines; + $text = ent($text); + $text =~ s{(https?://[^\s]+)}{<a href="$1">$1</a>}g; + return $text; } 1; diff --git a/templates/web/default/report/_main.html b/templates/web/default/report/_main.html index 53dcb9a13..0c0c74b16 100644 --- a/templates/web/default/report/_main.html +++ b/templates/web/default/report/_main.html @@ -11,11 +11,7 @@ </em></p> -[% FOREACH line IN split_into_lines( problem.detail ) %] -<p> -[% line | html %] -</p> -[% END %] +[% add_links( problem.detail ) | html_para %] [% INCLUDE 'report/photo.html' object=problem center=1 %] diff --git a/templates/web/default/report/updates.html b/templates/web/default/report/updates.html index c23d1409d..b7f44c5ae 100644 --- a/templates/web/default/report/updates.html +++ b/templates/web/default/report/updates.html @@ -16,11 +16,7 @@ </div> [%# update reporting %] <div class="update-text"> - [% FOREACH line IN split_into_lines( update.text ) %] - <p> - [% line | html %] - </p> - [% END %] + [% add_links( update.text ) | html_para %] [% INCLUDE 'report/photo.html' object=update %] </div> |