Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
72cc9f92
Commit
72cc9f92
authored
Aug 10, 2017
by
Sean McGivern
Committed by
Jose Ivan Vargas
Aug 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'mk-fix-case-insensitive-redirect-matching' into 'master'
Fix conflicting redirect search See merge request !13357
parent
345a304a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
27 deletions
+73
-27
app/models/redirect_route.rb
app/models/redirect_route.rb
+9
-1
changelogs/unreleased/mk-fix-case-insensitive-redirect-matching.yml
.../unreleased/mk-fix-case-insensitive-redirect-matching.yml
+4
-0
spec/models/redirect_route_spec.rb
spec/models/redirect_route_spec.rb
+10
-2
spec/models/route_spec.rb
spec/models/route_spec.rb
+50
-24
No files found.
app/models/redirect_route.rb
View file @
72cc9f92
...
...
@@ -8,5 +8,13 @@ class RedirectRoute < ActiveRecord::Base
presence:
true
,
uniqueness:
{
case_sensitive:
false
}
scope
:matching_path_and_descendants
,
->
(
path
)
{
where
(
'redirect_routes.path = ? OR redirect_routes.path LIKE ?'
,
path
,
"
#{
sanitize_sql_like
(
path
)
}
/%"
)
}
scope
:matching_path_and_descendants
,
->
(
path
)
do
wheres
=
if
Gitlab
::
Database
.
postgresql?
'LOWER(redirect_routes.path) = LOWER(?) OR LOWER(redirect_routes.path) LIKE LOWER(?)'
else
'redirect_routes.path = ? OR redirect_routes.path LIKE ?'
end
where
(
wheres
,
path
,
"
#{
sanitize_sql_like
(
path
)
}
/%"
)
end
end
changelogs/unreleased/mk-fix-case-insensitive-redirect-matching.yml
0 → 100644
View file @
72cc9f92
---
title
:
Fix destroy of case-insensitive conflicting redirects
merge_request
:
13357
author
:
spec/models/redirect_route_spec.rb
View file @
72cc9f92
...
...
@@ -20,8 +20,16 @@ describe RedirectRoute do
let!
(
:redirect4
)
{
group
.
redirect_routes
.
create
(
path:
'gitlabb/test/foo/bar'
)
}
let!
(
:redirect5
)
{
group
.
redirect_routes
.
create
(
path:
'gitlabb/test/baz'
)
}
context
'when the redirect route matches with same casing'
do
it
'returns correct routes'
do
expect
(
described_class
.
matching_path_and_descendants
(
'gitlabb/test'
)).
to
match_array
([
redirect2
,
redirect3
,
redirect4
,
redirect5
])
end
end
context
'when the redirect route matches with different casing'
do
it
'returns correct routes'
do
expect
(
described_class
.
matching_path_and_descendants
(
'GitLABB/test'
)).
to
match_array
([
redirect2
,
redirect3
,
redirect4
,
redirect5
])
end
end
end
end
spec/models/route_spec.rb
View file @
72cc9f92
...
...
@@ -145,11 +145,13 @@ describe Route do
describe
'#delete_conflicting_redirects'
do
context
'when a redirect route with the same path exists'
do
context
'when the redirect route has matching case'
do
let!
(
:redirect1
)
{
route
.
create_redirect
(
route
.
path
)
}
it
'deletes the redirect'
do
expect
do
route
.
delete_conflicting_redirects
expect
(
route
.
conflicting_redirects
).
to
be_empty
end
.
to
change
{
RedirectRoute
.
count
}.
by
(
-
1
)
end
context
'when redirect routes with paths descending from the route path exists'
do
...
...
@@ -159,19 +161,35 @@ describe Route do
let!
(
:other_redirect
)
{
route
.
create_redirect
(
"other"
)
}
it
'deletes all redirects with paths that descend from the route path'
do
expect
do
route
.
delete_conflicting_redirects
expect
(
route
.
conflicting_redirects
).
to
be_empty
end
.
to
change
{
RedirectRoute
.
count
}.
by
(
-
4
)
end
end
end
context
'when the redirect route is differently cased'
do
let!
(
:redirect1
)
{
route
.
create_redirect
(
route
.
path
.
upcase
)
}
it
'deletes the redirect'
do
expect
do
route
.
delete_conflicting_redirects
end
.
to
change
{
RedirectRoute
.
count
}.
by
(
-
1
)
end
end
end
end
describe
'#conflicting_redirects'
do
it
'returns an ActiveRecord::Relation'
do
expect
(
route
.
conflicting_redirects
).
to
be_an
(
ActiveRecord
::
Relation
)
end
context
'when a redirect route with the same path exists'
do
context
'when the redirect route has matching case'
do
let!
(
:redirect1
)
{
route
.
create_redirect
(
route
.
path
)
}
it
'returns the redirect route'
do
expect
(
route
.
conflicting_redirects
).
to
be_an
(
ActiveRecord
::
Relation
)
expect
(
route
.
conflicting_redirects
).
to
match_array
([
redirect1
])
end
...
...
@@ -182,10 +200,18 @@ describe Route do
let!
(
:other_redirect
)
{
route
.
create_redirect
(
"other"
)
}
it
'returns the redirect routes'
do
expect
(
route
.
conflicting_redirects
).
to
be_an
(
ActiveRecord
::
Relation
)
expect
(
route
.
conflicting_redirects
).
to
match_array
([
redirect1
,
redirect2
,
redirect3
,
redirect4
])
end
end
end
context
'when the redirect route is differently cased'
do
let!
(
:redirect1
)
{
route
.
create_redirect
(
route
.
path
.
upcase
)
}
it
'returns the redirect route'
do
expect
(
route
.
conflicting_redirects
).
to
match_array
([
redirect1
])
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment