Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
### Improvements

### Changes
- allow `.` in mentions (like `@bsky.brid.gy@bsky.brid.gy`)

### Bugfixes

Expand Down
10 changes: 5 additions & 5 deletions src/internal/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ export const language = P.createLanguage<TypeTable>({
const parser = P.seq(
notLinkLabel,
P.str('@'),
P.regexp(/[a-z0-9_-]+/i),
P.regexp(/[a-z0-9_.-]+/i),
P.seq(
P.str('@'),
P.regexp(/[a-z0-9_.-]+/i),
Expand Down 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
18 changes: 18 additions & 0 deletions test/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,12 @@ hoge`;
assert.deepStrictEqual(mfm.parse(input), output);
});

test('allow "." in username', () => {
const input = '@bsky.brid.gy@bsky.brid.gy';
const output = [MENTION('bsky.brid.gy', 'bsky.brid.gy', '@bsky.brid.gy@bsky.brid.gy')];
assert.deepStrictEqual(mfm.parse(input), output);
});

test('disallow "-" in head of username', () => {
const input = '@-abc';
const output = [TEXT('@-abc')];
Expand All @@ -745,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