Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33024757
D9883.1768393176.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D9883.1768393176.diff
View Options
diff --git a/lib/shared/markdown.js b/lib/shared/markdown.js
--- a/lib/shared/markdown.js
+++ b/lib/shared/markdown.js
@@ -347,6 +347,8 @@
);
}
+const ensRegex: RegExp = /^_?[a-zA-Z0-9-]{3,}\.eth$/;
+
export {
paragraphRegex,
paragraphStripTrailingNewlineRegex,
@@ -372,4 +374,5 @@
stripSpoilersFromNotifications,
stripSpoilersFromMarkdownAST,
parseChatMention,
+ ensRegex,
};
diff --git a/lib/shared/markdown.test.js b/lib/shared/markdown.test.js
--- a/lib/shared/markdown.test.js
+++ b/lib/shared/markdown.test.js
@@ -1,6 +1,6 @@
// @flow
-import { spoilerRegex } from './markdown.js';
+import { spoilerRegex, ensRegex } from './markdown.js';
import { chatMentionRegex } from './mention-utils.js';
// Each of the below tests is subject to the following RegEx pattern:
@@ -141,4 +141,43 @@
expect('@[256|1:test]]').not.toMatch(chatMentionRegex);
expect('@[[256|1:test]').not.toMatch(chatMentionRegex);
});
+
+ describe('ensRegex', () => {
+ it('should match all valid ENS names', () => {
+ expect('foo.eth').toMatch(ensRegex);
+ expect('jack.eth').toMatch(ensRegex);
+ expect('thisuserhasareallylongname.eth').toMatch(ensRegex);
+ expect('_foo.eth').toMatch(ensRegex);
+ expect('hello-world.eth').toMatch(ensRegex);
+ expect('_-special-chars-.eth').toMatch(ensRegex);
+ });
+
+ it('should not match any usernames names less than 3 characters', () => {
+ expect('fo.eth').not.toMatch(ensRegex);
+ expect('a.eth').not.toMatch(ensRegex);
+ expect('.eth').not.toMatch(ensRegex);
+ });
+
+ it('should not match any usernames with spaces', () => {
+ expect('foo bar.eth').not.toMatch(ensRegex);
+ expect('user1.eth user2.eth').not.toMatch(ensRegex);
+ expect('user1.eth and user2.eth').not.toMatch(ensRegex);
+ });
+
+ it('should not match any usernames with underscores not at the start', () => {
+ expect('foo_bar.eth').not.toMatch(ensRegex);
+ expect('user1_.eth').not.toMatch(ensRegex);
+ });
+
+ it('should not match any usernames without .eth', () => {
+ expect('foo').not.toMatch(ensRegex);
+ expect('ryan.eth2').not.toMatch(ensRegex);
+ });
+
+ it('should not match any usernames with special characters', () => {
+ expect('foo.eth!').not.toMatch(ensRegex);
+ expect('foo.eth#').not.toMatch(ensRegex);
+ expect('foo$.eth').not.toMatch(ensRegex);
+ });
+ });
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 14, 12:19 PM (5 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5931985
Default Alt Text
D9883.1768393176.diff (2 KB)
Attached To
Mode
D9883: [lib] Define a function that detects when an ENS name is typed
Attached
Detach File
Event Timeline
Log In to Comment