From ed5992c2054d276b4c19cbf2141a5dc8b964ab6d Mon Sep 17 00:00:00 2001 From: ca00740 Date: Tue, 10 May 2022 15:16:30 +0900 Subject: [PATCH 1/4] =?UTF-8?q?undefined=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/argBody.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/argBody.test.ts diff --git a/test/argBody.test.ts b/test/argBody.test.ts new file mode 100644 index 0000000..783fe30 --- /dev/null +++ b/test/argBody.test.ts @@ -0,0 +1,14 @@ +import * as argBody from "../src/argBody"; +import { LambdaBody } from "../src/Types/lambda"; + +test("bodyがundefinedの場合は例外を吐く", async () => { + const body: LambdaBody = { + text: undefined, + }; + + const expectError = new Error( + "引数が正しく渡されていません。もう一度helpを見てください。" + ); + + expect(() => argBody.parse(body)).toThrowError(expectError); +}); From 4ada07a64aa1d9a6dd2d9b4d847fda3c764ac601 Mon Sep 17 00:00:00 2001 From: ca00740 Date: Tue, 10 May 2022 15:16:55 +0900 Subject: [PATCH 2/4] =?UTF-8?q?undefined=E3=81=AEvalidation=E3=82=92?= =?UTF-8?q?=E5=85=88=E3=81=AB=E3=82=84=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/argBody.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/argBody.ts b/src/argBody.ts index 97880fd..cb6835a 100644 --- a/src/argBody.ts +++ b/src/argBody.ts @@ -2,13 +2,14 @@ import { LambdaBody } from "./Types/lambda"; import { ParseBody } from "./Types/utils"; export const parse = (body: LambdaBody): ParseBody => { - const args = body.text?.split(" "); - if (args === undefined) { + if (body.text === undefined) { throw new Error( "引数が正しく渡されていません。もう一度helpを見てください。" ); } + const args = body.text?.split(" "); + // 引数がないもしくは'--'が入ってるときはhelp const isHelp = args[0] === "" || args[0].includes("--"); // locationIdは数値5桁(prefecturesId2桁 + placeId3桁)のみ指定されている場合 From ee1bed6bff08c0068d1d99ae969d3a363764f82b Mon Sep 17 00:00:00 2001 From: ca00740 Date: Tue, 10 May 2022 15:25:31 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E5=85=A8=E8=A7=92=E3=82=B9=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/argBody.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/argBody.test.ts b/test/argBody.test.ts index 783fe30..339e318 100644 --- a/test/argBody.test.ts +++ b/test/argBody.test.ts @@ -12,3 +12,15 @@ test("bodyがundefinedの場合は例外を吐く", async () => { expect(() => argBody.parse(body)).toThrowError(expectError); }); + +test("bodyに全角スペースが含まれる場合は例外を吐く", async () => { + const body: LambdaBody = { + text: " 01101", + }; + + const expectError = new Error( + "全角スペースが含まれています。引数から削除してください。" + ); + + expect(() => argBody.parse(body)).toThrowError(expectError); +}); From 8a7885858e34962c9c5cc52a0d415bb2c40e8f91 Mon Sep 17 00:00:00 2001 From: ca00740 Date: Tue, 10 May 2022 15:25:54 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E5=85=A8=E8=A7=92=E3=82=B9=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E3=81=AEvalidation=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/argBody.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/argBody.ts b/src/argBody.ts index cb6835a..e2d8b92 100644 --- a/src/argBody.ts +++ b/src/argBody.ts @@ -8,6 +8,10 @@ export const parse = (body: LambdaBody): ParseBody => { ); } + if (body.text?.match(/.*\u3000.*/g) !== null) { + throw new Error("全角スペースが含まれています。引数から削除してください。"); + } + const args = body.text?.split(" "); // 引数がないもしくは'--'が入ってるときはhelp