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
This commit is contained in:
Rémy Coutable 2018-06-13 10:23:57 +00:00
commit a0a6e38b68
4 changed files with 26 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
title: Make quick commands case insensitive
merge_request: 19614
author: Jan Beckmann
type: fixed

View file

@ -39,7 +39,7 @@ module Gitlab
content.delete!("\r")
content.gsub!(commands_regex) do
if $~[:cmd]
commands << [$~[:cmd], $~[:arg]].reject(&:blank?)
commands << [$~[:cmd].downcase, $~[:arg]].reject(&:blank?)
''
else
$~[0]
@ -102,14 +102,14 @@ module Gitlab
# /close
^\/
(?<cmd>#{Regexp.union(names)})
(?<cmd>#{Regexp.new(Regexp.union(names).source, Regexp::IGNORECASE)})
(?:
[ ]
(?<arg>[^\n]*)
)?
(?:\n|$)
)
}mx
}mix
end
def perform_substitutions(content, commands)
@ -120,7 +120,7 @@ module Gitlab
end
substitution_definitions.each do |substitution|
match_data = substitution.match(content)
match_data = substitution.match(content.downcase)
if match_data
command = [substitution.name.to_s]
command << match_data[1] unless match_data[1].empty?

View file

@ -15,7 +15,7 @@ module Gitlab
return unless content
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
content
end

View file

@ -182,6 +182,14 @@ describe Gitlab::QuickActions::Extractor do
expect(msg).to eq "hello\nworld"
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
msg = %(hello\nworld\n/reopen\n/noop_command)
msg, commands = extractor.extract_commands(msg)
@ -206,6 +214,14 @@ describe Gitlab::QuickActions::Extractor do
expect(msg).to eq "hello\nworld\nthis is great? SHRUG"
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
msg = %(hello\nworld\n/reopen\n/substitution wow this is a thing.)
msg, commands = extractor.extract_commands(msg)