Skip to content

Commit 51de4ac

Browse files
Update placekey.js (#47)
* Update placekey.js * Update test.yml Updating node in test * Update test.yml Test updates * Removed yarn changes
1 parent 2dc2ce6 commit 51de4ac

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
- uses: actions/setup-node@v1
1818
with:
19-
node-version: 12.x
19+
node-version: 18.x
2020

2121
- name: Bootstrap
2222
run: |

src/lib/placekey.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ const REPLACEMENT_MAP_FORWARD = {
6565
const FIRST_TUPLE_REGEX = `[${ALPHABET}${REPLACEMENT_CHARS}${PADDING_CHAR}]{3}`;
6666
const TUPLE_REGEX = `[${ALPHABET}${REPLACEMENT_CHARS}]{3}`;
6767
const WHERE_REGEX = new RegExp(`^${[FIRST_TUPLE_REGEX, TUPLE_REGEX, TUPLE_REGEX].join('-')}$`);
68-
const WHAT_REGEX = new RegExp(`^[${ALPHABET}]{3,}(-[${ALPHABET}]{3,})?$`);
68+
const WHAT_REGEX_V1 = new RegExp(`^[${ALPHABET}]{3,}(-[${ALPHABET}]{3,})?$`);
69+
const WHAT_REGEX_V2 = new RegExp('^[01][abcdefghijklmnopqrstuvwxyz234567]{9}$');
6970

7071
// Boolean for whether or not a Placekey is valid.
7172
export function placekeyIsValid(placekey) {
@@ -82,7 +83,9 @@ export function placekeyIsValid(placekey) {
8283
}
8384

8485
if (what) {
85-
return Boolean(where.match(WHERE_REGEX) && what.match(WHAT_REGEX));
86+
return Boolean(
87+
where.match(WHERE_REGEX) && (what.match(WHAT_REGEX_V1) || what.match(WHAT_REGEX_V2))
88+
);
8689
}
8790
return Boolean(where.match(WHERE_REGEX));
8891
}

test/placekey.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ test('placekeyIsValid', t => {
5050
t.ok(placekeyIsValid('222-zzz@abc-234-xyz'), 'double tuple what with where');
5151
t.ok(placekeyIsValid('2222-zzz@5vg-7gq-tvz'), 'long address encoding with where');
5252
t.ok(placekeyIsValid('222-zzzz@5vg-7gq-tvz'), 'long poi encoding with where');
53+
t.ok(placekeyIsValid('1wvpg5h3st@628-tgw-z9f'), 'placekey fits V2');
5354
t.ok(
5455
placekeyIsValid('22222222-zzzzzzzzz@5vg-7gq-tvz'),
5556
'long address and poi encoding with where'

0 commit comments

Comments
 (0)