Resolve "Quick actions are case sensitive"

This commit is contained in:
Jan 2018-06-13 10:23:57 +00:00 committed by Rémy Coutable
parent df2efbdbec
commit 1721bbcb01
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.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
# /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
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?

View File

@ -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

View File

@ -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
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)