Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
c271fdc8
Commit
c271fdc8
authored
Aug 15, 2017
by
Jarka Kadlecova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't escape html entities when rich == raw line
parent
04f7f394
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
43 deletions
+62
-43
changelogs/unreleased/36041-notification-title.yml
changelogs/unreleased/36041-notification-title.yml
+4
-0
lib/gitlab/string_range_marker.rb
lib/gitlab/string_range_marker.rb
+22
-12
spec/helpers/diff_helper_spec.rb
spec/helpers/diff_helper_spec.rb
+4
-4
spec/lib/gitlab/diff/inline_diff_markdown_marker_spec.rb
spec/lib/gitlab/diff/inline_diff_markdown_marker_spec.rb
+3
-3
spec/lib/gitlab/diff/inline_diff_marker_spec.rb
spec/lib/gitlab/diff/inline_diff_marker_spec.rb
+7
-7
spec/lib/gitlab/string_range_marker_spec.rb
spec/lib/gitlab/string_range_marker_spec.rb
+22
-17
No files found.
changelogs/unreleased/36041-notification-title.yml
0 → 100644
View file @
c271fdc8
---
title
:
Don't escape html entities in InlineDiffMarkdownMarker
merge_request
:
author
:
lib/gitlab/string_range_marker.rb
View file @
c271fdc8
module
Gitlab
class
StringRangeMarker
attr_accessor
:raw_line
,
:rich_line
attr_accessor
:raw_line
,
:rich_line
,
:html_escaped
def
initialize
(
raw_line
,
rich_line
=
raw_line
)
@raw_line
=
raw_line
def
initialize
(
raw_line
,
rich_line
=
nil
)
@raw_line
=
raw_line
.
dup
if
rich_line
.
nil?
@rich_line
=
raw_line
.
dup
@html_escaped
=
false
else
@rich_line
=
ERB
::
Util
.
html_escape
(
rich_line
)
@html_escaped
=
true
end
end
def
mark
(
marker_ranges
)
return
rich_line
unless
marker_ranges
if
html_escaped
rich_marker_ranges
=
[]
marker_ranges
.
each
do
|
range
|
# Map the inline-diff range based on the raw line to character positions in the rich line
...
...
@@ -17,6 +24,9 @@ module Gitlab
# Turn the array of character positions into ranges
rich_marker_ranges
.
concat
(
collapse_ranges
(
rich_positions
))
end
else
rich_marker_ranges
=
marker_ranges
end
offset
=
0
# Mark each range
...
...
@@ -31,7 +41,7 @@ module Gitlab
offset
+=
text
.
length
-
original_text
.
length
end
rich_line
.
html_saf
e
@html_escaped
?
rich_line
.
html_safe
:
rich_lin
e
end
private
...
...
spec/helpers/diff_helper_spec.rb
View file @
c271fdc8
...
...
@@ -135,10 +135,10 @@ describe DiffHelper do
it
"returns strings with marked inline diffs"
do
marked_old_line
,
marked_new_line
=
mark_inline_diffs
(
old_line
,
new_line
)
expect
(
marked_old_line
).
to
eq
(
%q{abc <span class="idiff left right deletion">
'def'
</span>}
)
expect
(
marked_old_line
).
to
be_html_safe
expect
(
marked_new_line
).
to
eq
(
%q{abc <span class="idiff left right addition">
"def"
</span>}
)
expect
(
marked_new_line
).
to
be_html_safe
expect
(
marked_old_line
).
to
eq
(
%q{abc <span class="idiff left right deletion">
'def'
</span>}
)
expect
(
marked_old_line
).
not_
to
be_html_safe
expect
(
marked_new_line
).
to
eq
(
%q{abc <span class="idiff left right addition">
"def"
</span>}
)
expect
(
marked_new_line
).
not_
to
be_html_safe
end
end
...
...
spec/lib/gitlab/diff/inline_diff_markdown_marker_spec.rb
View file @
c271fdc8
...
...
@@ -6,9 +6,9 @@ describe Gitlab::Diff::InlineDiffMarkdownMarker do
let
(
:inline_diffs
)
{
[
2
..
5
]
}
let
(
:subject
)
{
described_class
.
new
(
raw
).
mark
(
inline_diffs
,
mode: :deletion
)
}
it
'marks the range'
do
expect
(
subject
).
to
eq
(
"ab{-c
'd-}ef'
"
)
expect
(
subject
).
to
be_html_safe
it
'
does not escape html etities and
marks the range'
do
expect
(
subject
).
to
eq
(
"ab{-c
'd-}ef'
"
)
expect
(
subject
).
not_
to
be_html_safe
end
end
end
spec/lib/gitlab/diff/inline_diff_marker_spec.rb
View file @
c271fdc8
...
...
@@ -2,11 +2,13 @@ require 'spec_helper'
describe
Gitlab
::
Diff
::
InlineDiffMarker
do
describe
'#mark'
do
context
"when the rich text is html safe"
do
let
(
:inline_diffs
)
{
[
2
..
5
]
}
let
(
:raw
)
{
"abc 'def'"
}
subject
{
described_class
.
new
(
raw
,
rich
).
mark
(
inline_diffs
)
}
context
"when the rich text is html safe"
do
let
(
:rich
)
{
%{<span class="abc">abc</span><span class="space"> </span><span class="def">'def'</span>}
.
html_safe
}
let
(
:inline_diffs
)
{
[
2
..
5
]
}
let
(
:subject
)
{
described_class
.
new
(
raw
,
rich
).
mark
(
inline_diffs
)
}
it
'marks the range'
do
expect
(
subject
).
to
eq
(
%{<span class="abc">ab<span class="idiff left">c</span></span><span class="space"><span class="idiff"> </span></span><span class="def"><span class="idiff right">'d</span>ef'</span>}
)
...
...
@@ -15,12 +17,10 @@ describe Gitlab::Diff::InlineDiffMarker do
end
context
"when the text text is not html safe"
do
let
(
:raw
)
{
"abc 'def'"
}
let
(
:inline_diffs
)
{
[
2
..
5
]
}
let
(
:subject
)
{
described_class
.
new
(
raw
).
mark
(
inline_diffs
)
}
let
(
:rich
)
{
"abc 'def' differs"
}
it
'marks the range'
do
expect
(
subject
).
to
eq
(
%{ab<span class="idiff left right">c 'd</span>ef'}
)
expect
(
subject
).
to
eq
(
%{ab<span class="idiff left right">c 'd</span>ef'
differs
}
)
expect
(
subject
).
to
be_html_safe
end
end
...
...
spec/lib/gitlab/string_range_marker_spec.rb
View file @
c271fdc8
...
...
@@ -2,34 +2,39 @@ require 'spec_helper'
describe
Gitlab
::
StringRangeMarker
do
describe
'#mark'
do
context
"when the rich text is html safe"
do
let
(
:raw
)
{
"abc <def>"
}
let
(
:rich
)
{
%{<span class="abc">abc</span><span class="space"> </span><span class="def"><def></span>}
.
html_safe
}
let
(
:inline_diffs
)
{
[
2
..
5
]
}
subject
do
def
mark_diff
(
rich
=
nil
)
raw
=
'abc <def>'
inline_diffs
=
[
2
..
5
]
described_class
.
new
(
raw
,
rich
).
mark
(
inline_diffs
)
do
|
text
,
left
:,
right
:|
"LEFT
#{
text
}
RIGHT"
end
end
context
"when the rich text is html safe"
do
let
(
:rich
)
{
%{<span class="abc">abc</span><span class="space"> </span><span class="def"><def></span>}
.
html_safe
}
it
'marks the inline diffs'
do
expect
(
subject
).
to
eq
(
%{<span class="abc">abLEFTcRIGHT</span><span class="space">LEFT RIGHT</span><span class="def">LEFT<dRIGHTef></span>}
)
expect
(
subject
).
to
be_html_safe
expect
(
mark_diff
(
rich
)
).
to
eq
(
%{<span class="abc">abLEFTcRIGHT</span><span class="space">LEFT RIGHT</span><span class="def">LEFT<dRIGHTef></span>}
)
expect
(
mark_diff
(
rich
)
).
to
be_html_safe
end
end
context
"when the rich text is not html safe"
do
let
(
:raw
)
{
"abc <def>"
}
let
(
:inline_diffs
)
{
[
2
..
5
]
}
subject
do
described_class
.
new
(
raw
).
mark
(
inline_diffs
)
do
|
text
,
left
:,
right
:|
"LEFT
#{
text
}
RIGHT"
context
'when rich text equals raw text'
do
it
'marks the inline diffs'
do
expect
(
mark_diff
).
to
eq
(
%{abLEFTc <dRIGHTef>}
)
expect
(
mark_diff
).
not_to
be_html_safe
end
end
context
'when rich text doeas not equal raw text'
do
let
(
:rich
)
{
"abc <def> differs"
}
it
'marks the inline diffs'
do
expect
(
subject
).
to
eq
(
%{abLEFTc <dRIGHTef>}
)
expect
(
subject
).
to
be_html_safe
expect
(
mark_diff
(
rich
)).
to
eq
(
%{abLEFTc <dRIGHTef> differs}
)
expect
(
mark_diff
(
rich
)).
to
be_html_safe
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment