Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support . in mentions #150

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 `@[email protected]`)

### 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 = '@[email protected]';
const output = [MENTION('bsky.brid.gy', 'bsky.brid.gy', '@[email protected]')];
assert.deepStrictEqual(mfm.parse(input), output);
});

easrng marked this conversation as resolved.
Show resolved Hide resolved
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 = '@[email protected]';
const output = [TEXT('@[email protected]')];
Expand Down