From 3a2d0e67aaf5cf5137c618ffe4b42b3d6b9aefd0 Mon Sep 17 00:00:00 2001 From: shibafu Date: Fri, 22 May 2020 00:27:32 +0900 Subject: [PATCH] =?UTF-8?q?=E5=8D=8A=E8=A7=92=E3=82=B9=E3=83=9A=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=82=92=E5=90=AB=E3=82=80=E3=82=BF=E3=82=B0=E3=81=AF?= =?UTF-8?q?=E5=8F=97=E3=81=91=E4=BB=98=E3=81=91=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/CheckinCsvImporter.php | 3 +++ tests/Unit/Services/CheckinCsvImporterTest.php | 10 ++++++++++ tests/fixture/Csv/tag-whitespace.utf8.csv | 2 ++ 3 files changed, 15 insertions(+) create mode 100644 tests/fixture/Csv/tag-whitespace.utf8.csv diff --git a/app/Services/CheckinCsvImporter.php b/app/Services/CheckinCsvImporter.php index c424dd1..834ca5f 100644 --- a/app/Services/CheckinCsvImporter.php +++ b/app/Services/CheckinCsvImporter.php @@ -178,6 +178,9 @@ class CheckinCsvImporter if (strpos($tag, "\n") !== false) { throw new CsvImportException("{$line} 行 : {$column}に改行を含めることはできません。"); } + if (strpos($tag, ' ') !== false) { + throw new CsvImportException("{$line} 行 : {$column}にスペースを含めることはできません。"); + } $tags[] = Tag::firstOrCreate(['name' => $tag]); if (count($tags) >= 32) { diff --git a/tests/Unit/Services/CheckinCsvImporterTest.php b/tests/Unit/Services/CheckinCsvImporterTest.php index 07c9be4..e3e9be3 100644 --- a/tests/Unit/Services/CheckinCsvImporterTest.php +++ b/tests/Unit/Services/CheckinCsvImporterTest.php @@ -240,6 +240,16 @@ class CheckinCsvImporterTest extends TestCase $importer->execute(); } + public function testTagCantAcceptWhitespaceUTF8() + { + $user = factory(User::class)->create(); + $this->expectException(CsvImportException::class); + $this->expectExceptionMessage('2 行 : タグ1にスペースを含めることはできません。'); + + $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/tag-whitespace.utf8.csv'); + $importer->execute(); + } + public function testTagCanAccept32ColumnsUTF8() { $user = factory(User::class)->create(); diff --git a/tests/fixture/Csv/tag-whitespace.utf8.csv b/tests/fixture/Csv/tag-whitespace.utf8.csv new file mode 100644 index 0000000..2e5f0ce --- /dev/null +++ b/tests/fixture/Csv/tag-whitespace.utf8.csv @@ -0,0 +1,2 @@ +日時,タグ1 +2020/01/23 06:01,"空白を含む タグ"