From f4799baf477bd4eff187dfea7eb7ec5d892ddfe4 Mon Sep 17 00:00:00 2001 From: Shannon Clarke Date: Mon, 18 Mar 2019 09:59:22 -0400 Subject: [PATCH 1/2] chore(issuer): ensure that the date is in YYYY format --- packages/polymath-issuer/public/whitelist-sample.csv | 8 ++++---- packages/polymath-issuer/src/utils/parsers/index.js | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/polymath-issuer/public/whitelist-sample.csv b/packages/polymath-issuer/public/whitelist-sample.csv index 9a638c6f3..f024782fc 100644 --- a/packages/polymath-issuer/public/whitelist-sample.csv +++ b/packages/polymath-issuer/public/whitelist-sample.csv @@ -1,5 +1,5 @@ ETH Address,Sell Restriction Date,Buy Restriction Date,KYC/AML Expiry Date,Can Buy From STO,Exempt From % Ownership,Is Accredited,Non-Accredited Limit -0x592E80AD45c08aba6C5bBd2d5C5A097BDF35Dee1,1/1/22,6/4/24,1/1/21,TRUE,TRUE,TRUE, -0xd9f346Bf88cA2cb7e11B0106018DE80A0169764D,12/21/30,12/21/30,10/10/24,TRUE,,TRUE, -0xA1833Cd1a3e72335DE0b6945b5d83247F234d6e8,,,12/1/25,,TRUE,,1000 -0x07889A89C6854bb4Ec445825E680255b17751192,,,12/1/25,TRUE,TRUE,, \ No newline at end of file +0x592E80AD45c08aba6C5bBd2d5C5A097BDF35Dee1,1/1/2022,6/4/2024,1/1/2021,TRUE,TRUE,TRUE, +0xd9f346Bf88cA2cb7e11B0106018DE80A0169764D,12/21/2030,12/21/2030,10/10/2024,TRUE,,TRUE, +0xA1833Cd1a3e72335DE0b6945b5d83247F234d6e8,,,12/1/2025,,TRUE,,1000 +0x07889A89C6854bb4Ec445825E680255b17751192,,,12/1/2025,TRUE,TRUE,, \ No newline at end of file diff --git a/packages/polymath-issuer/src/utils/parsers/index.js b/packages/polymath-issuer/src/utils/parsers/index.js index 3b6179795..6a2e5ae52 100644 --- a/packages/polymath-issuer/src/utils/parsers/index.js +++ b/packages/polymath-issuer/src/utils/parsers/index.js @@ -131,7 +131,11 @@ export function parseWhitelistCsv(file: string) { return false; } if (value.split('/').length === 3) { - return moment(value, ['MM/DD/YY', 'MM/DD/YYYY']).toDate(); + const year = value.split('/')[2]; + if (year.length < 4) { + return false; + } + return moment(value, 'MM/DD/YYYY').toDate(); } if (numericalRegex.test(value)) { return new BigNumber(value); From 6f71a39859224d2b4cd4ddc1e49895462c664870 Mon Sep 17 00:00:00 2001 From: Shannon Clarke Date: Wed, 20 Mar 2019 07:22:31 -0400 Subject: [PATCH 2/2] chore(issuer): update to use regex for check date format --- packages/polymath-issuer/src/utils/parsers/index.js | 7 ++----- packages/polymath-issuer/testUtils/fixtures/csvFiles.js | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/polymath-issuer/src/utils/parsers/index.js b/packages/polymath-issuer/src/utils/parsers/index.js index 6a2e5ae52..e0211ba93 100644 --- a/packages/polymath-issuer/src/utils/parsers/index.js +++ b/packages/polymath-issuer/src/utils/parsers/index.js @@ -131,11 +131,8 @@ export function parseWhitelistCsv(file: string) { return false; } if (value.split('/').length === 3) { - const year = value.split('/')[2]; - if (year.length < 4) { - return false; - } - return moment(value, 'MM/DD/YYYY').toDate(); + const regex = /\d\d?\/\d\d?\/\d{4}/; + return regex.test(value) && moment(value, 'M/D/YYYY').toDate(); } if (numericalRegex.test(value)) { return new BigNumber(value); diff --git a/packages/polymath-issuer/testUtils/fixtures/csvFiles.js b/packages/polymath-issuer/testUtils/fixtures/csvFiles.js index e44c9b4d4..f9388a3a5 100644 --- a/packages/polymath-issuer/testUtils/fixtures/csvFiles.js +++ b/packages/polymath-issuer/testUtils/fixtures/csvFiles.js @@ -1,9 +1,9 @@ export const validWhitelistCsv = `\ ETH Address,Sell Restriction Date,Buy Restriction Date,KYC/AML Expiry Date,Can Buy From STO,Exempt From % Ownership,Is Accredited,Non-Accredited Limit -0x592E80AD45c08aba6C5bBd2d5C5A097BDF35Dee1,1/1/22,6/4/24,1/1/21,TRUE,TRUE,FALSE, -0xd9f346Bf88cA2cb7e11B0106018DE80A0169764D,12/21/30,12/21/30,10/10/24,TRUE,,TRUE, -0xA1833Cd1a3e72335DE0b6945b5d83247F234d6e8,,,12/1/25,,TRUE,,1000 -0x07889A89C6854bb4Ec445825E680255b17751192,,,12/1/25,TRUE,TRUE,, +0x592E80AD45c08aba6C5bBd2d5C5A097BDF35Dee1,1/1/2022,6/4/2024,1/1/2021,TRUE,TRUE,FALSE, +0xd9f346Bf88cA2cb7e11B0106018DE80A0169764D,12/21/2030,12/21/2030,10/10/2024,TRUE,,TRUE, +0xA1833Cd1a3e72335DE0b6945b5d83247F234d6e8,,,12/1/2025,,TRUE,,1000 +0x07889A89C6854bb4Ec445825E680255b17751192,,,12/1/2025,TRUE,TRUE,, `; export const invalidWhitelistCsv = `\