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
a209d1e6
Unverified
Commit
a209d1e6
authored
1 year ago
by
Claire
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix ResolveURLService not resolving local URLs for remote content (#25637)
parent
4581a528
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/services/resolve_url_service.rb
+18
-3
18 additions, 3 deletions
app/services/resolve_url_service.rb
spec/services/resolve_url_service_spec.rb
+30
-0
30 additions, 0 deletions
spec/services/resolve_url_service_spec.rb
with
48 additions
and
3 deletions
app/services/resolve_url_service.rb
+
18
−
3
View file @
a209d1e6
...
...
@@ -89,13 +89,28 @@ class ResolveURLService < BaseService
def
process_local_url
recognized_params
=
Rails
.
application
.
routes
.
recognize_path
(
@url
)
return
unless
recognized_params
[
:action
]
==
'show'
case
recognized_params
[
:controller
]
when
'statuses'
return
unless
recognized_params
[
:action
]
==
'show'
if
recognized_params
[
:controller
]
==
'statuses'
status
=
Status
.
find_by
(
id:
recognized_params
[
:id
])
check_local_status
(
status
)
elsif
recognized_params
[
:controller
]
==
'accounts'
when
'accounts'
return
unless
recognized_params
[
:action
]
==
'show'
Account
.
find_local
(
recognized_params
[
:username
])
when
'home'
return
unless
recognized_params
[
:action
]
==
'index'
&&
recognized_params
[
:username_with_domain
].
present?
if
recognized_params
[
:any
]
&
.
match?
(
/\A[0-9]+\Z/
)
status
=
Status
.
find_by
(
id:
recognized_params
[
:any
])
check_local_status
(
status
)
elsif
recognized_params
[
:any
].
blank?
username
,
domain
=
recognized_params
[
:username_with_domain
].
gsub
(
/\A@/
,
''
).
split
(
'@'
)
return
unless
username
.
present?
&&
domain
.
present?
Account
.
find_remote
(
username
,
domain
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/services/resolve_url_service_spec.rb
+
30
−
0
View file @
a209d1e6
...
...
@@ -145,5 +145,35 @@ describe ResolveURLService, type: :service do
expect
(
subject
.
call
(
url
,
on_behalf_of:
account
)).
to
eq
(
status
)
end
end
context
'when searching for a local link of a remote private status'
do
let
(
:account
)
{
Fabricate
(
:account
)
}
let
(
:poster
)
{
Fabricate
(
:account
,
username:
'foo'
,
domain:
'example.com'
)
}
let
(
:url
)
{
'https://example.com/@foo/42'
}
let
(
:uri
)
{
'https://example.com/users/foo/statuses/42'
}
let!
(
:status
)
{
Fabricate
(
:status
,
url:
url
,
uri:
uri
,
account:
poster
,
visibility: :private
)
}
let
(
:search_url
)
{
"https://
#{
Rails
.
configuration
.
x
.
local_domain
}
/@foo@example.com/
#{
status
.
id
}
"
}
before
do
stub_request
(
:get
,
url
).
to_return
(
status:
404
)
if
url
.
present?
stub_request
(
:get
,
uri
).
to_return
(
status:
404
)
end
context
'when the account follows the poster'
do
before
do
account
.
follow!
(
poster
)
end
it
'returns the status'
do
expect
(
subject
.
call
(
search_url
,
on_behalf_of:
account
)).
to
eq
(
status
)
end
end
context
'when the account does not follow the poster'
do
it
'does not return the status'
do
expect
(
subject
.
call
(
search_url
,
on_behalf_of:
account
)).
to
be_nil
end
end
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