Commit 19f27e47 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'improved-banner-path-matching' into 'master'

Improved post receive banner path matching

See merge request gitlab-org/gitlab!59482
parents 197b9003 b6344fc3
......@@ -106,6 +106,14 @@ class BroadcastMessage < ApplicationRecord
return false if current_path.blank? && target_path.present?
return true if current_path.blank? || target_path.blank?
# Ensure paths are consistent across callers.
# This fixes a mismatch between requests in the GUI and CLI
#
# This has to be reassigned due to frozen strings being provided.
unless current_path.start_with?("/")
current_path = "/#{current_path}"
end
escaped = Regexp.escape(target_path).gsub('\\*', '.*')
regexp = Regexp.new "^#{escaped}$", Regexp::IGNORECASE
......
---
title: Fix for shell announcement banners
merge_request: 59482
author:
type: fixed
......@@ -120,6 +120,12 @@ RSpec.describe BroadcastMessage do
expect(subject.call('/users/name/issues').length).to eq(1)
end
it 'returns message if provided a path without a preceding slash' do
create(:broadcast_message, target_path: "/users/*/issues", broadcast_type: broadcast_type)
expect(subject.call('users/name/issues').length).to eq(1)
end
it 'returns the message for empty target path' do
create(:broadcast_message, target_path: "", broadcast_type: broadcast_type)
......
......@@ -264,7 +264,7 @@ RSpec.describe PostReceiveService do
context "project path matches" do
before do
allow(project).to receive(:full_path).and_return("/company/sekrit-project")
allow(project).to receive(:full_path).and_return("company/sekrit-project")
end
it "does output the latest scoped broadcast message" do
......
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