Commit 8ebd2bc8 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin Committed by James Lopez

Fix constraints for the Static Site Editor route

Previous MR:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/29453

**Problem**

Current id contraint does not allow routes with `.` symbol.

* `gitlab-org/gitlab-shell/-/sse/master/CONTRIBUTING` - match
* `gitlab-org/gitlab-shell/-/sse/master/CONTRIBUTING.md` - 404 page

**Solution**

This MR restores the previous value for `id` constraint.

I've added a simple integration test to make sure that routing works
as expected.
parent 77122449
......@@ -26,10 +26,6 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
scope '-' do
get 'archive/*id', constraints: { format: Gitlab::PathRegex.archive_formats_regex, id: /.+?/ }, to: 'repositories#archive', as: 'archive'
scope controller: :static_site_editor do
get '/sse/*id', action: :show, as: :show_sse
end
resources :artifacts, only: [:index, :destroy]
resources :jobs, only: [:index, :show], constraints: { id: /\d+/ } do
......
......@@ -21,6 +21,9 @@ resources :commit, only: [:show], constraints: { id: /\h{7,40}/ } do
end
end
# NOTE: Add new routes to repository_scoped.rb instead (see
# https://docs.gitlab.com/ee/development/routing.html#project-routes).
#
# Don't use format parameter as file extension (old 3.0.x behavior)
# See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments
scope format: false do
......
......@@ -30,5 +30,11 @@ scope format: false do
resources :protected_branches, only: [:index, :show, :create, :update, :destroy, :patch], constraints: { id: Gitlab::PathRegex.git_reference_regex }
resources :protected_tags, only: [:index, :show, :create, :update, :destroy]
scope constraints: { id: /[^\0]+/ } do
scope controller: :static_site_editor do
get '/sse/*id', action: :show, as: :show_sse
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'Static Site Editor' do
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
before do
project.add_maintainer(user)
sign_in(user)
visit project_show_sse_path(project, 'master/README.md')
end
it 'renders Static Site Editor page' do
expect(page).to have_selector('#static-site-editor')
end
end
......@@ -838,6 +838,13 @@ describe 'project routing' do
end
end
describe Projects::StaticSiteEditorController, 'routing' do
it 'routes to static_site_editor#show', :aggregate_failures do
expect(get('/gitlab/gitlabhq/-/sse/master/CONTRIBUTING.md')).to route_to('projects/static_site_editor#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/CONTRIBUTING.md')
expect(get('/gitlab/gitlabhq/-/sse/master/README')).to route_to('projects/static_site_editor#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/README')
end
end
describe Projects::EnvironmentsController, 'routing' do
describe 'legacy routing' do
it_behaves_like 'redirecting a legacy project path', "/gitlab/gitlabhq/environments", "/gitlab/gitlabhq/-/environments"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment