Commit a0a6e38b authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '47050-quick-actions-case-insensitive' into 'master'

Resolve "Quick actions are case sensitive"

Closes #47050

See merge request gitlab-org/gitlab-ce!19614
parents df2efbdb 1721bbcb
---
title: Make quick commands case insensitive
merge_request: 19614
author: Jan Beckmann
type: fixed
...@@ -39,7 +39,7 @@ module Gitlab ...@@ -39,7 +39,7 @@ module Gitlab
content.delete!("\r") content.delete!("\r")
content.gsub!(commands_regex) do content.gsub!(commands_regex) do
if $~[:cmd] if $~[:cmd]
commands << [$~[:cmd], $~[:arg]].reject(&:blank?) commands << [$~[:cmd].downcase, $~[:arg]].reject(&:blank?)
'' ''
else else
$~[0] $~[0]
...@@ -102,14 +102,14 @@ module Gitlab ...@@ -102,14 +102,14 @@ module Gitlab
# /close # /close
^\/ ^\/
(?<cmd>#{Regexp.union(names)}) (?<cmd>#{Regexp.new(Regexp.union(names).source, Regexp::IGNORECASE)})
(?: (?:
[ ] [ ]
(?<arg>[^\n]*) (?<arg>[^\n]*)
)? )?
(?:\n|$) (?:\n|$)
) )
}mx }mix
end end
def perform_substitutions(content, commands) def perform_substitutions(content, commands)
...@@ -120,7 +120,7 @@ module Gitlab ...@@ -120,7 +120,7 @@ module Gitlab
end end
substitution_definitions.each do |substitution| substitution_definitions.each do |substitution|
match_data = substitution.match(content) match_data = substitution.match(content.downcase)
if match_data if match_data
command = [substitution.name.to_s] command = [substitution.name.to_s]
command << match_data[1] unless match_data[1].empty? command << match_data[1] unless match_data[1].empty?
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
return unless content return unless content
all_names.each do |a_name| all_names.each do |a_name|
content.gsub!(%r{/#{a_name} ?(.*)$}, execute_block(action_block, context, '\1')) content.gsub!(%r{/#{a_name} ?(.*)$}i, execute_block(action_block, context, '\1'))
end end
content content
end end
......
...@@ -182,6 +182,14 @@ describe Gitlab::QuickActions::Extractor do ...@@ -182,6 +182,14 @@ describe Gitlab::QuickActions::Extractor do
expect(msg).to eq "hello\nworld" expect(msg).to eq "hello\nworld"
end end
it 'extracts command case insensitive' do
msg = %(hello\n/PoWer @user.name %9.10 ~"bar baz.2"\nworld)
msg, commands = extractor.extract_commands(msg)
expect(commands).to eq [['power', '@user.name %9.10 ~"bar baz.2"']]
expect(msg).to eq "hello\nworld"
end
it 'does not extract noop commands' do it 'does not extract noop commands' do
msg = %(hello\nworld\n/reopen\n/noop_command) msg = %(hello\nworld\n/reopen\n/noop_command)
msg, commands = extractor.extract_commands(msg) msg, commands = extractor.extract_commands(msg)
...@@ -206,6 +214,14 @@ describe Gitlab::QuickActions::Extractor do ...@@ -206,6 +214,14 @@ describe Gitlab::QuickActions::Extractor do
expect(msg).to eq "hello\nworld\nthis is great? SHRUG" expect(msg).to eq "hello\nworld\nthis is great? SHRUG"
end end
it 'extracts and performs substitution commands case insensitive' do
msg = %(hello\nworld\n/reOpen\n/sHRuG this is great?)
msg, commands = extractor.extract_commands(msg)
expect(commands).to eq [['reopen'], ['shrug', 'this is great?']]
expect(msg).to eq "hello\nworld\nthis is great? SHRUG"
end
it 'extracts and performs substitution commands with comments' do it 'extracts and performs substitution commands with comments' do
msg = %(hello\nworld\n/reopen\n/substitution wow this is a thing.) msg = %(hello\nworld\n/reopen\n/substitution wow this is a thing.)
msg, commands = extractor.extract_commands(msg) msg, commands = extractor.extract_commands(msg)
......
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