From 51de4ac7544d6ca56e3144cedff0a42f0f13f8e6 Mon Sep 17 00:00:00 2001 From: Jarred Parrett <91471796+jarredSafegraph@users.noreply.github.com> Date: Tue, 24 Sep 2024 11:13:19 -0400 Subject: [PATCH] Update placekey.js (#47) * Update placekey.js * Update test.yml Updating node in test * Update test.yml Test updates * Removed yarn changes --- .github/workflows/test.yml | 2 +- src/lib/placekey.js | 7 +++++-- test/placekey.spec.js | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5ec9135e..1dfa1f4b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 18.x - name: Bootstrap run: | diff --git a/src/lib/placekey.js b/src/lib/placekey.js index 6926d6e7..dfa711bd 100644 --- a/src/lib/placekey.js +++ b/src/lib/placekey.js @@ -65,7 +65,8 @@ const REPLACEMENT_MAP_FORWARD = { const FIRST_TUPLE_REGEX = `[${ALPHABET}${REPLACEMENT_CHARS}${PADDING_CHAR}]{3}`; const TUPLE_REGEX = `[${ALPHABET}${REPLACEMENT_CHARS}]{3}`; const WHERE_REGEX = new RegExp(`^${[FIRST_TUPLE_REGEX, TUPLE_REGEX, TUPLE_REGEX].join('-')}$`); -const WHAT_REGEX = new RegExp(`^[${ALPHABET}]{3,}(-[${ALPHABET}]{3,})?$`); +const WHAT_REGEX_V1 = new RegExp(`^[${ALPHABET}]{3,}(-[${ALPHABET}]{3,})?$`); +const WHAT_REGEX_V2 = new RegExp('^[01][abcdefghijklmnopqrstuvwxyz234567]{9}$'); // Boolean for whether or not a Placekey is valid. export function placekeyIsValid(placekey) { @@ -82,7 +83,9 @@ export function placekeyIsValid(placekey) { } if (what) { - return Boolean(where.match(WHERE_REGEX) && what.match(WHAT_REGEX)); + return Boolean( + where.match(WHERE_REGEX) && (what.match(WHAT_REGEX_V1) || what.match(WHAT_REGEX_V2)) + ); } return Boolean(where.match(WHERE_REGEX)); } diff --git a/test/placekey.spec.js b/test/placekey.spec.js index 38fac9fc..1028980d 100644 --- a/test/placekey.spec.js +++ b/test/placekey.spec.js @@ -50,6 +50,7 @@ test('placekeyIsValid', t => { t.ok(placekeyIsValid('222-zzz@abc-234-xyz'), 'double tuple what with where'); t.ok(placekeyIsValid('2222-zzz@5vg-7gq-tvz'), 'long address encoding with where'); t.ok(placekeyIsValid('222-zzzz@5vg-7gq-tvz'), 'long poi encoding with where'); + t.ok(placekeyIsValid('1wvpg5h3st@628-tgw-z9f'), 'placekey fits V2'); t.ok( placekeyIsValid('22222222-zzzzzzzzz@5vg-7gq-tvz'), 'long address and poi encoding with where'