Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
c38ad208
Commit
c38ad208
authored
9 years ago
by
Eugen Rochko
Browse files
Options
Downloads
Patches
Plain Diff
Fix mentions regex to exclude usernames in Medium URLs
parent
039e6f95
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/account.rb
+1
-1
1 addition, 1 deletion
app/models/account.rb
spec/models/account_spec.rb
+24
-0
24 additions, 0 deletions
spec/models/account_spec.rb
with
25 additions
and
1 deletion
app/models/account.rb
+
1
−
1
View file @
c38ad208
...
...
@@ -31,7 +31,7 @@ class Account < ActiveRecord::Base
has_many
:following
,
through: :active_relationships
,
source: :target_account
has_many
:followers
,
through: :passive_relationships
,
source: :account
MENTION_RE
=
/(?:^|\
W
)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i
MENTION_RE
=
/(?:^|\
s|\.
)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i
def
follow!
(
other_account
)
self
.
active_relationships
.
where
(
target_account:
other_account
).
first_or_create!
(
target_account:
other_account
)
...
...
This diff is collapsed.
Click to expand it.
spec/models/account_spec.rb
+
24
−
0
View file @
c38ad208
...
...
@@ -111,4 +111,28 @@ RSpec.describe Account, type: :model do
describe
'.find_local'
do
pending
end
describe
'MENTION_RE'
do
subject
{
Account
::
MENTION_RE
}
it
'matches usernames in the middle of a sentence'
do
expect
(
subject
.
match
(
'Hello to @alice from me'
)[
1
]).
to
eq
'alice'
end
it
'matches usernames in the beginning of status'
do
expect
(
subject
.
match
(
'@alice Hey how are you?'
)[
1
]).
to
eq
'alice'
end
it
'matches dot-prepended usernames'
do
expect
(
subject
.
match
(
'.@alice I want everybody to see this'
)[
1
]).
to
eq
'alice'
end
it
'does not match e-mails'
do
expect
(
subject
.
match
(
'Drop me an e-mail at alice@example.com'
)).
to
be_nil
end
it
'does not match URLs'
do
expect
(
subject
.
match
(
'Check this out https://medium.com/@alice/some-article#.abcdef123'
)).
to
be_nil
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment