Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab
Commits
823a57dd
There was an error fetching the commit references. Please try again later.
Verified
Commit
823a57dd
authored
2 weeks ago
by
Anush Kumar
Committed by
GitLab
2 weeks ago
Browse files
Options
Downloads
Patches
Plain Diff
Handled Multiline Regex
parent
20b82b09
No related branches found
No related tags found
1 merge request
!180946
Resolve "Update Import::UsernameMentionRewriter regex to catch newline and spaces."
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/gitlab/import/username_mention_rewriter.rb
+19
-12
19 additions, 12 deletions
lib/gitlab/import/username_mention_rewriter.rb
spec/lib/gitlab/import/username_mention_rewriter_spec.rb
+9
-0
9 additions, 0 deletions
spec/lib/gitlab/import/username_mention_rewriter_spec.rb
with
28 additions
and
12 deletions
lib/gitlab/import/username_mention_rewriter.rb
+
19
−
12
View file @
823a57dd
...
...
@@ -25,22 +25,29 @@ def update_username_mentions(relation_hash)
def
wrap_mentions_in_backticks
(
text
)
return
text
unless
text
.
present?
if
MENTION_REGEX
.
match?
(
text
)
text
=
MENTION_REGEX
.
replace_gsub
(
text
)
do
|
match
|
case
match
[
0
]
when
/^`/
match
[
0
]
when
/^ /
" `
#{
match
[
0
].
lstrip
}
`"
when
/^\(/
"(`
#{
match
[
0
].
sub
(
/^./
,
''
)
}
`"
else
"`
#{
match
[
0
]
}
`"
resultant_array
=
[]
split_array
=
text
.
split
(
"
\n
"
)
split_array
.
each
do
|
line
|
if
MENTION_REGEX
.
match?
(
line
)
line
=
MENTION_REGEX
.
replace_gsub
(
line
)
do
|
match
|
case
match
[
0
]
when
/^`/
match
[
0
]
when
/^ /
" `
#{
match
[
0
].
lstrip
}
`"
when
/^\(/
"(`
#{
match
[
0
].
sub
(
/^./
,
''
)
}
`"
else
"`
#{
match
[
0
]
}
`"
end
end
end
resultant_array
<<
line
end
text
resultant_array
.
join
(
"
\n
"
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/import/username_mention_rewriter_spec.rb
+
9
−
0
View file @
823a57dd
...
...
@@ -93,4 +93,13 @@
end
end
end
context
'when the text contains username in the new line'
do
let
(
:original_text
)
{
"Hello,
\n
@username is mentioned here.
\n
This is the next line."
}
let
(
:expected_text
)
{
"Hello,
\n
`@username` is mentioned here.
\n
This is the next line."
}
it
'wraps the username in backticks and it should be properly formatted in the new line'
do
expect
(
instance
.
wrap_mentions_in_backticks
(
original_text
)).
to
eq
(
expected_text
)
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment