Skip to content

Commit

Permalink
disallow "." at head and tail of username
Browse files Browse the repository at this point in the history
  • Loading branch information
easrng committed Dec 9, 2024
1 parent 554b1fc commit 35243ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/internal/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ export const language = P.createLanguage<TypeTable>({
}
}
}
// remove "-" of tail of username
// remove [.-] of tail of username
let modifiedName = username;
result = /-+$/.exec(username);
result = /[.-]+$/.exec(username);
if (result != null) {
if (modifiedHost == null) {
modifiedName = username.slice(0, (-1 * result[0].length));
Expand All @@ -597,8 +597,8 @@ export const language = P.createLanguage<TypeTable>({
invalidMention = true;
}
}
// disallow "-" of head of username
if (modifiedName.length === 0 || modifiedName[0] === '-') {
// disallow [.-] of head of username
if (modifiedName.length === 0 || /^[.-]/.test(modifiedName)) {
invalidMention = true;
}
// disallow [.-] of head of hostname
Expand Down
12 changes: 12 additions & 0 deletions test/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,18 @@ hoge`;
assert.deepStrictEqual(mfm.parse(input), output);
});

test('disallow "." in head of username', () => {
const input = '@.abc';
const output = [TEXT('@.abc')];
assert.deepStrictEqual(mfm.parse(input), output);
});

test('disallow "." in tail of username', () => {
const input = '@abc.';
const output = [MENTION('abc', null, '@abc'), TEXT('.')];
assert.deepStrictEqual(mfm.parse(input), output);
});

test('disallow "." in head of hostname', () => {
const input = '@abc@.aaa';
const output = [TEXT('@abc@.aaa')];
Expand Down

0 comments on commit 35243ec

Please sign in to comment.