------------------------------------------------------------------------------------------
[EC-CUBE] 2.13.1
[レンタルサーバ] ローカルサーバー
[OS] Windows 8.1
[PHP] PHP 5.5.9
[データベース] MySQL 5.6.14
[WEBサーバ] Apache 2.4.7
[ブラウザ] Firefox 27.0
[現象] 管理画面の各所フォームでファイル名を入力した際に警告がエラーログに記録される。
------------------------------------------------------------------------------------------
いつもお世話になっております。
管理画面の「コンテンツ管理>ファイル管理」でフォルダ作成を作成する際に、ファイル名を指定して送信すると以下の警告が data/logs/error.log に記録されます。
2014/02/13 21:11:39 [/dev/eccube-2.13.1/html/admin/contents/file_manager.php] Warning(E_WARNING): preg_match(): Compilation failed: missing terminating ] for character class at offset 3 on [E:\Www\dev\eccube-2.13.1\data\class\SC_CheckError.php(854)] from ::1
原因は SC_CheckError::FILE_NAME_CHECK_BY_NOUPLOAD() 内で使われている '/[\\]/' という正規表現だと考えます。
この問題に対する修正パッチを作成致しましたので、
よろしければ取り込んで頂けないでしょうか?
お手数をおかけしますがご検討のほどよろしくお願いいたします。
Index: data/class/SC_CheckError.php
===================================================================
--- data/class/SC_CheckError.php (リビジョン 23289)
+++ data/class/SC_CheckError.php (作業コピー)
@@ -851,7 +851,7 @@
return;
}
$this->createParam($value);
- if (strlen($this->arrParam[$value[1]]) > 0 && !preg_match("/^[[:alnum:]_\.-]+$/i", $this->arrParam[$value[1]]) || preg_match('/[\\]/' ,$this->arrParam[$value[1]])) {
+ if (preg_match("/[^[:alnum:]_.\\-]/", $this->arrParam[$value[1]])) {
$this->arrErr[$value[1]] = '※ ' . $value[0] . 'のファイル名に日本語やスペースは使用しないで下さい。<br />';
}
}
※追記
該当箇所の単体テストがありませんでしたので用意致しました。
Index: tests/class/SC_CheckError/SC_CheckError_FILE_NAME_CHECK_BY_NOUPLOADTest.php
===================================================================
--- tests/class/SC_CheckError/SC_CheckError_FILE_NAME_CHECK_BY_NOUPLOADTest.php (revision 0)
+++ tests/class/SC_CheckError/SC_CheckError_FILE_NAME_CHECK_BY_NOUPLOADTest.php (revision 0)
@@ -0,0 +1,76 @@
+<?php
+/*
+ * This file is part of EC-CUBE
+ *
+ * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+$HOME = realpath(dirname(__FILE__)) . "/../../..";
+require_once($HOME . "/tests/class/Common_TestCase.php");
+
+class SC_CheckError_FILE_NAME_CHECK_BY_NOUPLOADTest extends Common_TestCase
+{
+ public function testFILE_NAME_CHECK_BY_NOUPLOAD_空文字列の場合_エラーをセットしない()
+ {
+ $arrForm = array('file' => '');
+ $objErr = new SC_CheckError_Ex($arrForm);
+ $objErr->doFunc(array('label', 'file') ,array('FILE_NAME_CHECK_BY_NOUPLOAD'));
+
+ $this->expected = false;
+ $this->actual = isset($objErr->arrErr['file']);
+ $this->verify();
+ }
+
+ public function testFILE_NAME_CHECK_BY_NOUPLOAD_使用できない文字が含まれていない場合_エラーをセットしない()
+ {
+ $arrForm = array('file' => 'a_b-c.Z');
+ $objErr = new SC_CheckError_Ex($arrForm);
+ $objErr->doFunc(array('label', 'file') ,array('FILE_NAME_CHECK_BY_NOUPLOAD'));
+
+ $this->expected = false;
+ $this->actual = isset($objErr->arrErr['file']);
+ $this->verify();
+ }
+
+ public function testFILE_NAME_CHECK_BY_NOUPLOAD_使用できない文字が含まれている場合_エラーをセットする()
+ {
+ $arrForm = array('file' => 'a/b');
+ $objErr = new SC_CheckError_Ex($arrForm);
+ $objErr->doFunc(array('label', 'file') ,array('FILE_NAME_CHECK_BY_NOUPLOAD'));
+
+ $this->expected = '※ labelのファイル名に日本語やスペースは使用しないで下さい。<br />';
+ $this->actual = $objErr->arrErr['file'];
+ $this->verify();
+ }
+
+ /**
+ * @depends testFILE_NAME_CHECK_BY_NOUPLOAD_使用できない文字が含まれている場合_エラーをセットする
+ */
+ public function testFILE_NAME_CHECK_BY_NOUPLOAD_他のエラーが既にセットされている場合_エラーを上書きしない()
+ {
+ $arrForm = array('file' => 'a/b');
+ $objErr = new SC_CheckError_Ex($arrForm);
+ $objErr->arrErr['file'] = $other_error = 'Unknown error.';
+ $objErr->doFunc(array('label', 'file') ,array('FILE_NAME_CHECK_BY_NOUPLOAD'));
+
+ $this->expected = $other_error;
+ $this->actual = $objErr->arrErr['file'];
+ $this->verify();
+ }
+}
----------------
Seiji Nitta
zenith6@gmail.com
https://github.com/zenith6/