Skip to content

Instantly share code, notes, and snippets.

@zenith6
Created February 14, 2014 11:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zenith6/8999302 to your computer and use it in GitHub Desktop.
Save zenith6/8999302 to your computer and use it in GitHub Desktop.
EC-CUBEの 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 (strlen($this->arrParam[$value[1]]) > 0 && 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 (リビジョン 0)
+++ tests/class/SC_CheckError/SC_CheckError_FILE_NAME_CHECK_BY_NOUPLOADTest.php (作業コピー)
@@ -0,0 +1,105 @@
+<?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 validValueProvider()
+ {
+ return array(
+ array('a'),
+ array('012'),
+ array('abc012'),
+ array('a.txt'),
+ array('a-b.zip'),
+ array('a-b_c.tar.gz'),
+ );
+ }
+
+ public function invalidValueProvider()
+ {
+ return array(
+ array("line1\nline2"),
+ array("a\x00b"),
+ array('a/b'),
+ array('a b'),
+ array('日本語'),
+ );
+ }
+
+ 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();
+ }
+
+ /**
+ * @dataProvider validValueProvider
+ */
+ public function testFILE_NAME_CHECK_BY_NOUPLOAD_使用できない文字が含まれていない場合_エラーをセットしない($value)
+ {
+ $arrForm = array('file' => $value);
+ $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();
+ }
+
+ /**
+ * @dataProvider invalidValueProvider
+ */
+ public function testFILE_NAME_CHECK_BY_NOUPLOAD_使用できない文字が含まれている場合_エラーをセットする($value)
+ {
+ $arrForm = array('file' => $value);
+ $objErr = new SC_CheckError_Ex($arrForm);
+ $objErr->doFunc(array('label', 'file') ,array('FILE_NAME_CHECK_BY_NOUPLOAD'));
+
+ $this->expected = true;
+ $this->actual = isset($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();
+ }
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment