LoginSignup
0
1

More than 5 years have passed since last update.

TeamPassのitem一覧でdescriptionのトリミングがマルチバイトを理解しない問題の対策

Posted at

TeamPass というパスワード管理ツールがあるのですが、項目一覧で説明(description)のところを30文字に切り詰める処理がマルチバイト理解しないので、変なところで切り詰められてしまいます。

とりあえず substr() を mb_substr() に変更することで回避しました。
できれば文字幅を考慮すべきですが、実害がないのでマルチバイトでも30文字のままにしています。

sources/items.queries.php- sources/items.queries.php
--- sources/items.queries.php-  2016-08-16 05:03:17.000000000 +0900
+++ sources/items.queries.php   2016-11-29 17:53:16.128242854 +0900
@@ -314,7 +314,7 @@
                 '&nbsp;<a id="fileclass'.$newID.'" class="file" onclick="AfficherDetailsItem(\''.$newID.'\', \'0\', \'\', \'\', \'\', \'\', \'\')" ondblclick="AfficherDetailsItem(\''.$newID.'\', \'0\', \'\', \'\', \'\', true, \'\')">' .
                 stripslashes($dataReceived['label']);
                 if (!empty($dataReceived['description']) && isset($_SESSION['settings']['show_description']) && $_SESSION['settings']['show_description'] == 1) {
-                    $html .= '&nbsp;<font size=2px>['.strip_tags(stripslashes(substr(cleanString($dataReceived['description']), 0, 30))).']</font>';
+                    $html .= '&nbsp;<font size=2px>['.strip_tags(stripslashes(mb_substr(cleanString($dataReceived['description']), 0, 30))).']</font>';
                 }
                 $html .= '</a><span style="float:right;margin:2px 10px 0px 0px;">';
                 // mini icon for collab
@@ -1955,9 +1955,9 @@
                         if (!empty($record['description']) && isset($_SESSION['settings']['show_description']) && $_SESSION['settings']['show_description'] == 1) {
                             $tempo = explode("<br />", $record['description']);
                             if (count($tempo) == 1) {
-                                $html .= '&nbsp;<font size="2px">['.strip_tags(stripslashes(substr(cleanString($record['description']), 0, 30))).']</font>';
+                                $html .= '&nbsp;<font size="2px">['.strip_tags(stripslashes(mb_substr(cleanString($record['description']), 0, 30))).']</font>';
                             } else {
-                                $html .= '&nbsp;<font size="2px">['.strip_tags(stripslashes(substr(cleanString($tempo[0]), 0, 30))).']</font>';
+                                $html .= '&nbsp;<font size="2px">['.strip_tags(stripslashes(mb_substr(cleanString($tempo[0]), 0, 30))).']</font>';
                             }
                         }
                         $html .= '</a>';
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1