Skip to content

Commit

Permalink
Fix support for usernames ending in dashes
Browse files Browse the repository at this point in the history
Closes GH-13.
  • Loading branch information
wooorm committed Aug 11, 2018
1 parent 1689ec6 commit b9e7e2d
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 21 deletions.
6 changes: 4 additions & 2 deletions lib/index.js
Expand Up @@ -23,14 +23,16 @@ try {
} catch (err) {}

/* Username may only contain alphanumeric characters or
* single hyphens, and cannot begin or end with a hyphen.
* single hyphens, and cannot begin or end with a hyphen*.
*
* \* That is: until https://github.com/remarkjs/remark-github/issues/13.
*
* `PERSON` is either a user or an organization, but also
* matches a team:
*
* https://github.com/blog/1121-introducing-team-mentions
*/
var NAME = '(?:[a-z0-9]{1,2}|[a-z0-9][a-z0-9-]{1,37}[a-z0-9])'
var NAME = '(?:[a-z0-9]{1,2}|[a-z0-9][a-z0-9-]{1,38})'
var USER = '(' + NAME + ')'
var PROJECT = '((?:[_A-Za-z0-9-]|\\.git[_A-Za-z0-9-]|\\.(?!git))+)'
var REPO = USER + '\\/' + PROJECT
Expand Down
8 changes: 2 additions & 6 deletions lib/util/username-end.js
Expand Up @@ -30,12 +30,8 @@ function username(value, fromIndex) {

size = index - fromIndex

/* Last character of username cannot be a dash. */
if (
!size ||
size > MAX_USER_LENGTH ||
value.charCodeAt(index - 1) === CC_DASH
) {
/* Last character of username can no longer be a dash, but could be (GH-13). */
if (!size || size > MAX_USER_LENGTH) {
return -1
}

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/issue-project/input.md
Expand Up @@ -13,7 +13,9 @@ wooorm/remark#1
and here
wooorm/remark#1

Usernames: this is not a valid, -wooorm/remark#1; nor is this wooorm-/remark#1; but this is w-w/remark#1, and so is w/remark#1 and ww/remark#1.
Usernames: this is not a valid, -wooorm/remark#1; but this is w-w/remark#1, and so is w/remark#1 and ww/remark#1.

Note that this is no longer valid, but used to be: w-/remark#1.

Project names: this is not a valid, wooorm/c.git#1; but this is wooorm/c#1, so is w/w#1, and ww/.gitconfig#1.

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/issue-project/output.md
Expand Up @@ -13,7 +13,9 @@ They work here
and here
[wooorm/remark#1](https://github.com/wooorm/remark/issues/1)

Usernames: this is not a valid, -wooorm/remark#1; nor is this wooorm-/remark#1; but this is [w-w/remark#1](https://github.com/w-w/remark/issues/1), and so is [w/remark#1](https://github.com/w/remark/issues/1) and [ww/remark#1](https://github.com/ww/remark/issues/1).
Usernames: this is not a valid, -wooorm/remark#1; but this is [w-w/remark#1](https://github.com/w-w/remark/issues/1), and so is [w/remark#1](https://github.com/w/remark/issues/1) and [ww/remark#1](https://github.com/ww/remark/issues/1).

Note that this is no longer valid, but used to be: [w-/remark#1](https://github.com/w-/remark/issues/1).

Project names: this is not a valid, wooorm/c.git#1; but this is [wooorm/c#1](https://github.com/wooorm/c/issues/1), so is [w/w#1](https://github.com/w/w/issues/1), and [ww/.gitconfig#1](https://github.com/ww/.gitconfig/issues/1).

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/issue-user/input.md
Expand Up @@ -13,6 +13,6 @@ wooorm#1
and here
wooorm#1

This is not a valid, -wooorm#1; nor is this wooorm-#1; but this is w-w#1, and so is w#1 and ww#1.
This is not a valid, -wooorm#1; but this is w-w#1, and so is w#1 and ww#1, and w-#1 used to be valid.

This is too long: wooormwooormwooormwooormwooormwooormwooo#1 (40 character username).
2 changes: 1 addition & 1 deletion test/fixtures/issue-user/output.md
Expand Up @@ -13,6 +13,6 @@ They work here
and here
[wooorm#1](https://github.com/wooorm/remark/issues/1)

This is not a valid, -wooorm#1; nor is this wooorm-#1; but this is [w-w#1](https://github.com/w-w/remark/issues/1), and so is [w#1](https://github.com/w/remark/issues/1) and [ww#1](https://github.com/ww/remark/issues/1).
This is not a valid, -wooorm#1; but this is [w-w#1](https://github.com/w-w/remark/issues/1), and so is [w#1](https://github.com/w/remark/issues/1) and [ww#1](https://github.com/ww/remark/issues/1), and [w-#1](https://github.com/w-/remark/issues/1) used to be valid.

This is too long: wooormwooormwooormwooormwooormwooormwooo#1 (40 character username).
6 changes: 5 additions & 1 deletion test/fixtures/mention/input.md
Expand Up @@ -8,4 +8,8 @@ Additionally, GitHub does something funny with @mention’s and @mentions.

Some valid real world examples: @a, @github, @github/security.

But these names are invalid: @-w, @w-, but this is: @w-w.
But this is invalid: @-w.

This is valid: @w-w.

This used to be valid: @w-
6 changes: 5 additions & 1 deletion test/fixtures/mention/output.md
Expand Up @@ -8,4 +8,8 @@ Additionally, GitHub does something funny with [**@mention**](https://github.com

Some valid real world examples: [**@a**](https://github.com/a), [**@github**](https://github.com/github), [**@github/security**](https://github.com/github/security).

But these names are invalid: @-w, @w-, but this is: [**@w-w**](https://github.com/w-w).
But this is invalid: @-w.

This is valid: [**@w-w**](https://github.com/w-w).

This used to be valid: [**@w-**](https://github.com/w-)
4 changes: 2 additions & 2 deletions test/fixtures/reference-advanced/output.md
Expand Up @@ -2,11 +2,11 @@

Multiple slashes: foo/bar/baz@0000000, foo/bar/baz#1, [**@foo/bar**](https://github.com/foo/bar)/baz.

Dashes around slashes: foobar-/baz@0000000, foobar-/baz#1.
Dashes around slashes: [foobar-/baz@`0000000`](https://github.com/foobar-/baz/commit/0000000), [foobar-/baz#1](https://github.com/foobar-/baz/issues/1).

Upper-case projects: [foobar/bAz@`0000000`](https://github.com/foobar/bAz/commit/0000000), [foobar/Baz#1](https://github.com/foobar/Baz/issues/1).

@foo-/bar, @foo/-bar.
[**@foo-/bar**](https://github.com/foo-/bar), @foo/-bar.

[f/b#1](https://github.com/f/b/issues/1). [f/b#0](https://github.com/f/b/issues/0). [f/b@`0000000`](https://github.com/f/b/commit/0000000).

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/sha-project/input.md
Expand Up @@ -56,6 +56,8 @@ Or here

And these SHAs which could also be words? wooorm/remark@deedeed, and wooorm/remark@fabaceae.

Usernames: this is not a valid, -wooorm/remark@0000000; nor is this wooorm-/remark@0000000; but this is w-w/remark@0000000, and so is w/remark@0000000 and ww/remark@0000000.
Usernames: this is not a valid, -wooorm/remark@0000000; but this is w-w/remark@0000000, and so is w/remark@0000000 and ww/remark@0000000.

This used to be valid: wooorm-/remark@0000000.

Project names: this is not a valid, wooorm/c.git@0000000; but this is wooorm/c@0000000, so is w/w@0000000, and ww/.gitconfig@0000000.
4 changes: 3 additions & 1 deletion test/fixtures/sha-project/output.md
Expand Up @@ -56,6 +56,8 @@ Or here

And these SHAs which could also be words? [wooorm/remark@`deedeed`](https://github.com/wooorm/remark/commit/deedeed), and [wooorm/remark@`fabacea`](https://github.com/wooorm/remark/commit/fabaceae).

Usernames: this is not a valid, -wooorm/remark@0000000; nor is this wooorm-/remark@0000000; but this is [w-w/remark@`0000000`](https://github.com/w-w/remark/commit/0000000), and so is [w/remark@`0000000`](https://github.com/w/remark/commit/0000000) and [ww/remark@`0000000`](https://github.com/ww/remark/commit/0000000).
Usernames: this is not a valid, -wooorm/remark@0000000; but this is [w-w/remark@`0000000`](https://github.com/w-w/remark/commit/0000000), and so is [w/remark@`0000000`](https://github.com/w/remark/commit/0000000) and [ww/remark@`0000000`](https://github.com/ww/remark/commit/0000000).

This used to be valid: [wooorm-/remark@`0000000`](https://github.com/wooorm-/remark/commit/0000000).

Project names: this is not a valid, wooorm/c.git@0000000; but this is [wooorm/c@`0000000`](https://github.com/wooorm/c/commit/0000000), so is [w/w@`0000000`](https://github.com/w/w/commit/0000000), and [ww/.gitconfig@`0000000`](https://github.com/ww/.gitconfig/commit/0000000).
4 changes: 3 additions & 1 deletion test/fixtures/sha-user/input.md
Expand Up @@ -56,7 +56,9 @@ Or here

And these SHAs which could also be words? wooorm@deedeed, and wooorm@fabaceae.

This is not a valid, -wooorm@0000000; nor is this wooorm-@0000000; but this is w-w@0000000, and so is w@0000000 and ww@0000000.
This is not a valid, -wooorm@0000000; but this is w-w@0000000, and so is w@0000000 and ww@0000000.

This used to be valid: wooorm-@0000000.

And here’s an example of a disposable e-mail domain, which starts with 7 hexidecimal characters: wooorm@deadaddress.com, which shouldn’t match, because there’s no word break after the SHA-like part.

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/sha-user/output.md
Expand Up @@ -56,7 +56,9 @@ Or here

And these SHAs which could also be words? [wooorm@`deedeed`](https://github.com/wooorm/remark/commit/deedeed), and [wooorm@`fabacea`](https://github.com/wooorm/remark/commit/fabaceae).

This is not a valid, -wooorm@0000000; nor is this wooorm-@0000000; but this is [w-w@`0000000`](https://github.com/w-w/remark/commit/0000000), and so is [w@`0000000`](https://github.com/w/remark/commit/0000000) and [ww@`0000000`](https://github.com/ww/remark/commit/0000000).
This is not a valid, -wooorm@0000000; but this is [w-w@`0000000`](https://github.com/w-w/remark/commit/0000000), and so is [w@`0000000`](https://github.com/w/remark/commit/0000000) and [ww@`0000000`](https://github.com/ww/remark/commit/0000000).

This used to be valid: [wooorm-@`0000000`](https://github.com/wooorm-/remark/commit/0000000).

And here’s an example of a disposable e-mail domain, which starts with 7 hexidecimal characters: wooorm@deadaddress.com, which shouldn’t match, because there’s no word break after the SHA-like part.

Expand Down
3 changes: 2 additions & 1 deletion test/index.js
Expand Up @@ -114,7 +114,8 @@ var repositories = [
],
['mame/_', 'mame', '_'],
['github/.gitignore', 'github', '.gitignore'],
['github/.gitc', 'github', '.gitc']
['github/.gitc', 'github', '.gitc'],
['Qix-/color-convert', 'Qix-', 'color-convert']
]

test('Repositories', function(t) {
Expand Down

0 comments on commit b9e7e2d

Please sign in to comment.