Commit 9a0cfd61 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch '357255-ajk-quick-actions-escaped-underscore' into 'master'

Handle underscores in user quick actions

See merge request gitlab-org/gitlab!83987
parents 6f3e31f7 740a84f1
......@@ -77,7 +77,10 @@ module QuickActions
# want to also handle bare usernames. The ReferenceExtractor also has
# different behaviour, and will return all group members for groups named
# using a user-style reference, which is not in scope here.
#
# nb: underscores may be passed in escaped to protect them from markdown rendering
args = params.split(/\s|,/).select(&:present?).uniq - ['and']
args.map! { _1.gsub(/\\_/, '_') }
usernames = (args - ['me']).map { _1.delete_prefix('@') }
found = User.by_username(usernames).to_a.select { can?(:read_user, _1) }
found_names = found.map(&:username).to_set
......
......@@ -671,6 +671,19 @@ RSpec.describe QuickActions::InterpretService do
end
shared_examples 'assign command' do
it 'assigns to users with escaped underscores' do
user = create(:user)
base = user.username
user.update!(username: "#{base}_")
issuable.project.add_developer(user)
cmd = "/assign @#{base}\\_"
_, updates, _ = service.execute(cmd, issuable)
expect(updates).to eq(assignee_ids: [user.id])
end
it 'assigns to a single user' do
_, updates, _ = service.execute(content, issuable)
......
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