Commit 740a84f1 authored by Alex Kalderimis's avatar Alex Kalderimis

Handle escaped underscores in usernames

Underscores may need to be escaped due to being embedded in markdown.

Changelog: fixed
parent ae5b9e31
...@@ -77,7 +77,10 @@ module QuickActions ...@@ -77,7 +77,10 @@ module QuickActions
# want to also handle bare usernames. The ReferenceExtractor also has # want to also handle bare usernames. The ReferenceExtractor also has
# different behaviour, and will return all group members for groups named # different behaviour, and will return all group members for groups named
# using a user-style reference, which is not in scope here. # 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 = params.split(/\s|,/).select(&:present?).uniq - ['and']
args.map! { _1.gsub(/\\_/, '_') }
usernames = (args - ['me']).map { _1.delete_prefix('@') } usernames = (args - ['me']).map { _1.delete_prefix('@') }
found = User.by_username(usernames).to_a.select { can?(:read_user, _1) } found = User.by_username(usernames).to_a.select { can?(:read_user, _1) }
found_names = found.map(&:username).to_set found_names = found.map(&:username).to_set
......
...@@ -671,6 +671,19 @@ RSpec.describe QuickActions::InterpretService do ...@@ -671,6 +671,19 @@ RSpec.describe QuickActions::InterpretService do
end end
shared_examples 'assign command' do 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 it 'assigns to a single user' do
_, updates, _ = service.execute(content, issuable) _, 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