Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
8152584c
Commit
8152584c
authored
8 years ago
by
Eugen Rochko
Browse files
Options
Downloads
Patches
Plain Diff
Fix #142 - Escape ILIKE special characters from Account.find_remote
parent
20aa777c
No related branches found
Branches containing commit
No related tags found
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
+42
-2
42 additions, 2 deletions
spec/models/account_spec.rb
with
43 additions
and
3 deletions
app/models/account.rb
+
1
−
1
View file @
8152584c
...
...
@@ -142,7 +142,7 @@ class Account < ApplicationRecord
end
def
find_remote!
(
username
,
domain
)
where
(
arel_table
[
:username
].
matches
(
username
)).
where
(
domain
.
nil?
?
{
domain:
nil
}
:
arel_table
[
:domain
].
matches
(
domain
)).
take!
where
(
arel_table
[
:username
].
matches
(
username
.
gsub
(
/[%_]/
,
'\\\\\0'
)
)).
where
(
domain
.
nil?
?
{
domain:
nil
}
:
arel_table
[
:domain
].
matches
(
domain
.
gsub
(
/[%_]/
,
'\\\\\0'
)
)).
take!
end
def
find_local
(
username
)
...
...
This diff is collapsed.
Click to expand it.
spec/models/account_spec.rb
+
42
−
2
View file @
8152584c
...
...
@@ -107,11 +107,51 @@ RSpec.describe Account, type: :model do
end
describe
'.find_local'
do
pending
before
do
Fabricate
(
:account
,
username:
'Alice'
)
end
it
'returns Alice for alice'
do
expect
(
Account
.
find_local
(
'alice'
)).
to_not
be_nil
end
it
'returns Alice for Alice'
do
expect
(
Account
.
find_local
(
'Alice'
)).
to_not
be_nil
end
it
'does not return anything for a_ice'
do
expect
(
Account
.
find_local
(
'a_ice'
)).
to
be_nil
end
it
'does not return anything for al%'
do
expect
(
Account
.
find_local
(
'al%'
)).
to
be_nil
end
end
describe
'.find_remote'
do
pending
before
do
Fabricate
(
:account
,
username:
'Alice'
,
domain:
'mastodon.social'
)
end
it
'returns Alice for alice@mastodon.social'
do
expect
(
Account
.
find_remote
(
'alice'
,
'mastodon.social'
)).
to_not
be_nil
end
it
'returns Alice for ALICE@MASTODON.SOCIAL'
do
expect
(
Account
.
find_remote
(
'ALICE'
,
'MASTODON.SOCIAL'
)).
to_not
be_nil
end
it
'does not return anything for a_ice@mastodon.social'
do
expect
(
Account
.
find_remote
(
'a_ice'
,
'mastodon.social'
)).
to
be_nil
end
it
'does not return anything for alice@m_stodon.social'
do
expect
(
Account
.
find_remote
(
'alice'
,
'm_stodon.social'
)).
to
be_nil
end
it
'does not return anything for alice@m%'
do
expect
(
Account
.
find_remote
(
'alice'
,
'm%'
)).
to
be_nil
end
end
describe
'MENTION_RE'
do
...
...
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