Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
a34ec8396cae
Commit
150b4f66
authored
Jan 22, 2016
by
Douwe Maan
Browse files
Make sure non-highlighted diffs are still escaped
parent
77f7b6ba3c94
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/controllers/projects/blob_controller.rb
View file @
a34ec839
...
...
@@ -52,7 +52,9 @@ def update
def
preview
@content
=
params
[
:content
]
diffy
=
Diffy
::
Diff
.
new
(
@blob
.
data
,
@content
,
diff:
'-U 3'
,
include_diff_info:
true
)
@diff_lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diffy
.
diff
.
scan
(
/.*\n/
))
diff_lines
=
diffy
.
diff
.
scan
(
/.*\n/
)[
2
..-
1
]
diff_lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diff_lines
)
@diff_lines
=
Gitlab
::
Diff
::
Highlight
.
new
(
diff_lines
).
highlight
render
layout:
false
end
...
...
app/models/note.rb
View file @
a34ec839
...
...
@@ -244,7 +244,7 @@ def truncated_diff_lines
prev_match_line
=
nil
prev_lines
=
[]
diff_lines
.
each
do
|
line
|
highlighted_
diff_lines
.
each
do
|
line
|
if
line
.
type
==
"match"
prev_lines
.
clear
prev_match_line
=
line
...
...
@@ -261,7 +261,11 @@ def truncated_diff_lines
end
def
diff_lines
@diff_lines
||=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diff
.
diff
.
lines
.
to_a
)
@diff_lines
||=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diff
.
diff
.
lines
)
end
def
highlighted_diff_lines
Gitlab
::
Diff
::
Highlight
.
new
(
diff_lines
).
highlight
end
def
discussion_id
...
...
lib/gitlab/diff/highlight.rb
View file @
a34ec839
module
Gitlab
module
Diff
class
Highlight
attr_reader
:diff_file
attr_reader
:diff_file
,
:diff_lines
,
:raw_lines
delegate
:old_path
,
:new_path
,
:old_ref
,
:new_ref
,
to: :diff_file
,
prefix: :diff
def
initialize
(
diff_file
)
@diff_file
=
diff_file
@diff_lines
=
diff_file
.
diff_lines
def
initialize
(
diff_lines
)
if
diff_lines
.
is_a?
(
Gitlab
::
Diff
::
File
)
@diff_file
=
diff_file
@diff_lines
=
diff_file
.
diff_lines
else
@diff_lines
=
diff_lines
end
@raw_lines
=
@diff_lines
.
map
(
&
:text
)
end
...
...
@@ -31,7 +35,7 @@ def highlight
private
def
highlight_line
(
diff_line
,
index
)
return
html_escape
(
diff_line
.
text
)
unless
diff_file
.
diff_refs
return
html_escape
(
diff_line
.
text
)
unless
diff_file
&&
diff_file
.
diff_refs
line_prefix
=
diff_line
.
text
.
match
(
/\A(.)/
)
?
$1
:
' '
...
...
@@ -52,10 +56,12 @@ def inline_diffs
end
def
old_lines
return
unless
diff_file
@old_lines
||=
Gitlab
::
Highlight
.
highlight_lines
(
*
processing_args
(
:old
))
end
def
new_lines
return
unless
diff_file
@new_lines
||=
Gitlab
::
Highlight
.
highlight_lines
(
*
processing_args
(
:new
))
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