Commit d17b0580 authored by Robert May's avatar Robert May

Move path fix to broadcast_message model

parent 6f1f5c71
...@@ -106,6 +106,14 @@ class BroadcastMessage < ApplicationRecord ...@@ -106,6 +106,14 @@ class BroadcastMessage < ApplicationRecord
return false if current_path.blank? && target_path.present? return false if current_path.blank? && target_path.present?
return true if current_path.blank? || target_path.blank? 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('\\*', '.*') escaped = Regexp.escape(target_path).gsub('\\*', '.*')
regexp = Regexp.new "^#{escaped}$", Regexp::IGNORECASE regexp = Regexp.new "^#{escaped}$", Regexp::IGNORECASE
......
...@@ -81,12 +81,8 @@ class PostReceiveService ...@@ -81,12 +81,8 @@ class PostReceiveService
banner = nil banner = nil
if project if project
# This provides the path in a similar manner to the frontend passing scoped_messages = BroadcastMessage.current_banner_messages(project.full_path).select do |message|
# the request path, improving regex matching. message.target_path.present? && message.matches_current_path(project.full_path)
path = "/#{project.full_path}"
scoped_messages = BroadcastMessage.current_banner_messages(path).select do |message|
message.target_path.present? && message.matches_current_path(path)
end end
banner = scoped_messages.last banner = scoped_messages.last
......
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