Skip to content

Commit 5712653

Browse files
committed
fix(core): do not allow comma as invalid handle
also add whitespace cases in for handle tests and add doc comment
1 parent c70a64e commit 5712653

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
/**
2+
* From ADA Handle FAQ:
3+
* Alphanumeric: [a-z][A-Z][0-9]
4+
* Dash: -
5+
* Underscore: _
6+
* Period: .
7+
* Pipe: | (in general it is not valid, but an exception exists in mainnet)
8+
*/
19
export const isValidHandle = (handle: string) => {
2-
const pattern = /^[\w,.|\-]*@{0,1}[\w,.|\-]+$/;
10+
const pattern = /^[\w.|\-]*@{0,1}[\w.|\-]+$/;
311
return pattern.test(handle);
412
};

packages/core/test/Asset/util/isValidHandle.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const validHandles = [
44
'bob',
55
'a',
66
'alice',
7+
'_',
78
'test-handle',
89
'test.handle',
910
'test-handle-123',
@@ -12,6 +13,7 @@ const validHandles = [
1213
'handle_name',
1314
'@alice',
1415
'test-@handle',
16+
'_@_',
1517
'0|0',
1618
'0|0@0|0'
1719
];
@@ -25,6 +27,12 @@ const invalidHandles = [
2527
'ada%1_test',
2628
'lace ',
2729
'wallet ',
30+
'comma,',
31+
'comma,@sub',
32+
'sub@comma,',
33+
'\n',
34+
'\r',
35+
' ',
2836
'sub@sub@handle'
2937
];
3038

0 commit comments

Comments
 (0)