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,"空白を含む タグ"