Commit e6b68548 authored by David Kim's avatar David Kim

Merge branch 'include-branch-name-in-invalid-alert' into 'master'

Include branch name(s) in "is invalid" alert

See merge request gitlab-org/gitlab!62380
parents 82dfcec7 002a380f
......@@ -79,11 +79,11 @@ class Projects::CompareController < Projects::ApplicationController
private
def validate_refs!
valid = [head_ref, start_ref].map { |ref| valid_ref?(ref) }
invalid = [head_ref, start_ref].filter { |ref| !valid_ref?(ref) }
return if valid.all?
return if invalid.empty?
flash[:alert] = "Invalid branch name"
flash[:alert] = "Invalid branch name(s): #{invalid.join(', ')}"
redirect_to project_compare_index_path(source_project)
end
......
......@@ -156,7 +156,7 @@ RSpec.describe Projects::CompareController do
it 'shows a flash message and redirects' do
show_request
expect(flash[:alert]).to eq('Invalid branch name')
expect(flash[:alert]).to eq("Invalid branch name(s): master%' AND 2554=4423 AND '%'='")
expect(response).to have_gitlab_http_status(:found)
end
end
......@@ -169,7 +169,20 @@ RSpec.describe Projects::CompareController do
it 'shows a flash message and redirects' do
show_request
expect(flash[:alert]).to eq('Invalid branch name')
expect(flash[:alert]).to eq("Invalid branch name(s): master%' AND 2554=4423 AND '%'='")
expect(response).to have_gitlab_http_status(:found)
end
end
context 'when the both refs are invalid' do
let(:from_project_id) { nil }
let(:from_ref) { "master%' AND 2554=4423 AND '%'='" }
let(:to_ref) { "improve%' =,awesome" }
it 'shows a flash message and redirects' do
show_request
expect(flash[:alert]).to eq("Invalid branch name(s): improve%' =,awesome, master%' AND 2554=4423 AND '%'='")
expect(response).to have_gitlab_http_status(:found)
end
end
......
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