OSDN Git Service

use format_htmltext() helper instead of escape_title()
authorhylom <hylom@users.sourceforge.jp>
Thu, 14 Feb 2019 11:52:03 +0000 (20:52 +0900)
committerhylom <hylom@users.sourceforge.jp>
Thu, 14 Feb 2019 11:52:03 +0000 (20:52 +0900)
src/newslash_web/lib/Newslash/Plugin/NewslashHelpers.pm
src/newslash_web/lib/Newslash/Web/Controller/API/Comment.pm
src/newslash_web/lib/Newslash/Web/Controller/API/Journal.pm
src/newslash_web/lib/Newslash/Web/Controller/API/Submission.pm
src/newslash_web/lib/Newslash/Web/Controller/API/deprecated/Post.pm
src/newslash_web/t/plugins/newslash_helpers.t [new file with mode: 0644]

index c0bb405..601cf45 100644 (file)
@@ -124,6 +124,7 @@ sub _format_htmltext {
         $allowed = $c->app->config->{Editor}->{allowed_tags};
     }
     else {
+        $c->app->log->warn("NewslashHelper::_format_htmltext: invalid type - '$type'");
         $allowed = $c->app->config->{Editor}->{allowed_tags};
     }
     return Newslash::Util::TextFormatter::escape_html($allowed, $text);
index 9e89528..3832410 100644 (file)
@@ -27,7 +27,7 @@ sub post {
     my $data = $c->req->json;
     my $message = "";
 
-    $params->{title} = $c->escape_title($data->{title});
+    $params->{title} = $c->format_htmltext($data->{title}, "title");
     $params->{comment} = $c->format_htmltext($data->{comment}, "comment");
     $params->{discussion_id} = $data->{discussion_id};
     $params->{stoid} = $data->{stoid};
index ed9ed8e..391832c 100644 (file)
@@ -68,7 +68,7 @@ sub post {
     my $item = $data->{item};
     my $message = "";
 
-    $params->{description} = $c->escape_title($item->{title});
+    $params->{description} = $c->format_htmltext($item->{title}, "text");
     $message = "no title!" if !$params->{description};
 
     # check user is valid
index 480badd..8987957 100644 (file)
@@ -100,7 +100,7 @@ sub post {
     $message = "no_content" if (!$params->{introtext} && !$item->{url});
 
     # check title
-    $params->{title} = $c->escape_title($item->{title});
+    $params->{title} = $c->format_htmltext($item->{title}, "title");
     $message = "no_title" if !$params->{title};
 
     # check URL
index 30e7071..9550cee 100644 (file)
@@ -22,7 +22,7 @@ EOT
     my $allowed = decode_json($allowed_tags);
     my $data = $c->req->json;
 
-    $params->{title} = $c->escape_title($data->{title});
+    $params->{title} = $c->format_htmltext($data->{title}, "title");
     $params->{url} = $data->{url};
     $params->{email} = $data->{email};
     $params->{introtext} = $c->clean_html($allowed, $data->{introtext});
@@ -75,7 +75,7 @@ EOT
     my $data = $c->req->json;
     my $message = "";
 
-    $params->{title} = $c->escape_title($data->{title});
+    $params->{title} = $c->format_htmltext($data->{title}, "title");
     $message = "no title!" if !$params->{title};
 
     $params->{time} = $data->{createtime};
@@ -153,7 +153,7 @@ EOT
     my $data = $c->req->json;
     my $message = "";
 
-    $params->{title} = $c->escape_title($data->{title});
+    $params->{title} = $c->format_htmltext($data->{title}, "title");
     $params->{comment} = $c->clean_html($allowed, $data->{comment});
     $params->{sid} = $data->{discussion_id};
     $params->{stoid} = $data->{stoid};
diff --git a/src/newslash_web/t/plugins/newslash_helpers.t b/src/newslash_web/t/plugins/newslash_helpers.t
new file mode 100644 (file)
index 0000000..692c0ce
--- /dev/null
@@ -0,0 +1,36 @@
+# -*-Perl-*-
+# PostFilter plugin tests
+
+use Mojo::Base -strict;
+use Test::More;
+use Test::Mojo;
+
+use Newslash::Util::TestMan;
+use Data::Dumper;
+use Newslash::Eventd::Handlers;
+
+my $t = Test::Mojo->new('Newslash::Web');
+
+subtest 'text formatter test' => sub {
+    my $text = <<EOT;
+<p>insiderman曰く、</p><blockquote
+><p>はやくも来年発表されるとみられているiPhoneの新モデルの噂が出始めている(<a href="https://www.theverge.com/circuitbreaker/2017/11/13/16644266/apple-iphone-x-plus-rumor-two-fullscreen-phones-2018">The Verge</a>、<a href="http://jbpress.ismedia.jp/articles/-/51619">JBPress</a>、<a href="https://hardware.slashdot.org/story/17/11/14/000224/apple-could-launch-two-new-full-screen-iphones-next-year">Slashdot</a>)。</p>
+<p>KGI SecuritiesのアナリストMing-Chi Kuo氏による予想では、6.5インチ有機ELディスプレイを搭載したモデルがiPhone Xの新たなモデル(「Plus」バージョン)として出るのではないか、とされている。また、iPhone 8 Plusと同等のサイズでiPhone Xのようにフルスクリーン化した6.1インチ液晶ディスプレイ搭載モデルも出る可能性があるとも予測されている。これは、「ハイエンド市場」のさまざまな需要を狙ったものになるという。iPhone Xはその価格も話題となったが、液晶ディスプレイの採用で価格を下げることができるようだ。</p>
+</blockquote>
+EOT
+
+    my $correct = <<EOT;
+<p>insiderman曰く、</p>
+<blockquote>
+<p>はやくも来年発表されるとみられているiPhoneの新モデルの噂が出始めている(<a href="https://www.theverge.com/circuitbreaker/2017/11/13/16644266/apple-iphone-x-plus-rumor-two-fullscreen-phones-2018">The Verge</a>、<a href="http://jbpress.ismedia.jp/articles/-/51619">JBPress</a>、<a href="https://hardware.slashdot.org/story/17/11/14/000224/apple-could-launch-two-new-full-screen-iphones-next-year">Slashdot</a>)。</p>
+<p>KGI SecuritiesのアナリストMing-Chi Kuo氏による予想では、6.5インチ有機ELディスプレイを搭載したモデルがiPhone Xの新たなモデル(「Plus」バージョン)として出るのではないか、とされている。また、iPhone 8 Plusと同等のサイズでiPhone Xのようにフルスクリーン化した6.1インチ液晶ディスプレイ搭載モデルも出る可能性があるとも予測されている。これは、「ハイエンド市場」のさまざまな需要を狙ったものになるという。iPhone Xはその価格も話題となったが、液晶ディスプレイの採用で価格を下げることができるようだ。</p>
+</blockquote>
+EOT
+
+    my $rs = $t->app->format_htmltext($text, "story");
+    cmp_ok($correct, "eq", $rs, "format_htmltext");
+
+
+};
+
+done_testing();