OSDN Git Service

Model::Util: add escape_plaintext method
authorhylom <hylom@users.sourceforge.jp>
Mon, 7 Nov 2016 15:21:22 +0000 (00:21 +0900)
committerhylom <hylom@users.sourceforge.jp>
Mon, 7 Nov 2016 15:21:22 +0000 (00:21 +0900)
src/newslash_web/lib/Newslash/Model/Util.pm

index d9a5abe..8227012 100644 (file)
@@ -83,4 +83,38 @@ sub escape_html {
     return EscapeHTML::escape($allowed, $html);
 }
 
+
+=head2 escape_plaintext($text)
+
+escape  HTML
+
+=over 4
+
+=item Parameters
+
+=over 4
+
+=item $text
+
+input plain text
+
+=back
+
+=item Return value
+
+escaped text
+
+=back
+
+=cut
+
+sub escape_plaintext {
+    my ($self, $text) = @_;
+
+    my $t = $text->replace(qr/&(?!|lt;|gt;)/, '&amp;');
+    $t = $t->replace(qr/</, '&lt;');
+    $t = $t->replace(qr/>/, '&gt;');
+    return $t;
+}
+
 1;