-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #550 from tienifr/fix/move-autoEmail-to-before-men…
…tions
- Loading branch information
Showing
4 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1063,3 +1063,63 @@ test('Skip rendering invalid markdown',() => { | |
testString = '> *This is multiline\nbold text*'; | ||
expect(parser.replace(testString)).toBe('<blockquote>*This is multiline</blockquote>bold text*'); | ||
}); | ||
|
||
test('Test for email with [email protected]@gmail.com', () => { | ||
const testString = '[email protected]@gmail.com'; | ||
const resultString = '<a href=\"mailto:[email protected]\">[email protected]</a>@gmail.com'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test for email with [email protected]@gmail.com', () => { | ||
const testString = '[email protected]@gmail.com'; | ||
const resultString = '<a href=\"mailto:[email protected]\">[email protected]</a>@gmail.com'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test for email with test@[email protected]', () => { | ||
const testString = 'test@[email protected]'; | ||
const resultString = 'test@<a href=\"mailto:[email protected]\">[email protected]</a>'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test for email with test+1@[email protected]', () => { | ||
const testString = 'test+1@[email protected]'; | ||
const resultString = 'test+1@<a href=\"mailto:[email protected]\">[email protected]</a>'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test user mention with @[email protected]', () => { | ||
const testString = '@[email protected]'; | ||
const resultString = '<mention-user>@[email protected]</mention-user>'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test user mention with @[email protected]', () => { | ||
const testString = '@[email protected]'; | ||
const resultString = '<mention-user>@[email protected]</mention-user>'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test user mention with @[email protected]', () => { | ||
const testString = '@[email protected]'; | ||
const resultString = '<mention-user>@[email protected]</mention-user>'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test here mention with @here_@here_.com', () => { | ||
const testString = '@here_@here_.com'; | ||
const resultString = '<mention-here>@here</mention-here><em><mention-here>@here</mention-here></em>.com'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test here mention with @here@', () => { | ||
const testString = '@here@'; | ||
const resultString = '<mention-here>@here</mention-here>@'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); | ||
|
||
test('Test here mention with @here@here', () => { | ||
const testString = '@here@here'; | ||
const resultString = '<mention-here>@here</mention-here><mention-here>@here</mention-here>'; | ||
expect(parser.replace(testString)).toBe(resultString); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,6 @@ describe('Str.isValidMention', () => { | |
expect(Str.isValidMention('*@[email protected]*')).toBeTruthy(); | ||
expect(Str.isValidMention(' @[email protected]')).toBeTruthy(); | ||
expect(Str.isValidMention('~@[email protected]~')).toBeTruthy(); | ||
expect(Str.isValidMention('#@[email protected]')).toBeTruthy(); | ||
expect(Str.isValidMention('_@[email protected]_')).toBeTruthy(); | ||
expect(Str.isValidMention('`@[email protected]`')).toBeFalsy(); | ||
expect(Str.isValidMention('\'@[email protected]\'')).toBeTruthy(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -943,8 +943,16 @@ const Str = { | |
* @returns {bool} | ||
*/ | ||
isValidMention(mention) { | ||
// A valid mention starts with a space, *, _, #, ', ", or @ (with no preceding characters). | ||
return /[\s*~_#'"@]/g.test(mention.charAt(0)); | ||
// Mentions can start @ proceeded by a space, eg "ping @[email protected]" | ||
if (/[\s@]/g.test(mention.charAt(0))) { | ||
return true; | ||
} | ||
|
||
// Mentions can also start and end with a *, _, ~, ', or " (with no other preceding characters) | ||
// eg "ping *@[email protected]*" | ||
const firstChar = mention.charAt(0); | ||
const lastChar = mention.charAt(mention.length - 1); | ||
return /[*~_'"]/g.test(firstChar) && /[*~_'"]/g.test(lastChar) && firstChar === lastChar; | ||
}, | ||
|
||
/** | ||
|