Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a010db5d
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a010db5d
编写于
1月 20, 2016
作者:
D
Douwe Maan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Properly handle HTML entities with inline diffs
上级
88bd1385
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
24 addition
and
20 deletion
+24
-20
lib/gitlab/diff/inline_diff.rb
lib/gitlab/diff/inline_diff.rb
+4
-7
lib/gitlab/diff/inline_diff_marker.rb
lib/gitlab/diff/inline_diff_marker.rb
+14
-2
lib/gitlab/diff/parser.rb
lib/gitlab/diff/parser.rb
+1
-6
spec/lib/gitlab/diff/inline_diff_marker_spec.rb
spec/lib/gitlab/diff/inline_diff_marker_spec.rb
+4
-4
spec/lib/gitlab/diff/parser_spec.rb
spec/lib/gitlab/diff/parser_spec.rb
+1
-1
未找到文件。
lib/gitlab/diff/inline_diff.rb
浏览文件 @
a010db5d
...
...
@@ -16,15 +16,12 @@ module Gitlab
old_line
=
@lines
[
old_index
]
new_line
=
@lines
[
new_index
]
suffixless_old_line
=
old_line
[
1
..-
1
]
suffixless_new_line
=
new_line
[
1
..-
1
]
# Skip inline diff if empty line was replaced with content
next
if
suffixless_old_line
==
""
next
if
old_line
[
1
..-
1
]
==
""
# Add one, because this is based on the
suf
fixless version
lcp
=
longest_common_prefix
(
suffixless_old_line
,
suffixless_new_line
)
+
1
lcs
=
longest_common_suffix
(
suffixless_old_line
,
suffixless_new_line
)
# Add one, because this is based on the
pre
fixless version
lcp
=
longest_common_prefix
(
old_line
[
1
..-
1
],
new_line
[
1
..-
1
]
)
+
1
lcs
=
longest_common_suffix
(
old_line
[
lcp
..-
1
],
new_line
[
lcp
..-
1
]
)
old_diff_range
=
lcp
..
(
old_line
.
length
-
lcs
-
1
)
new_diff_range
=
lcp
..
(
new_line
.
length
-
lcs
-
1
)
...
...
lib/gitlab/diff/inline_diff_marker.rb
浏览文件 @
a010db5d
...
...
@@ -12,7 +12,7 @@ module Gitlab
offset
=
0
line_inline_diffs
.
each
do
|
inline_diff_range
|
# Map the inline-diff range based on the raw line to character positions in the rich line
inline_diff_positions
=
position_mapping
[
inline_diff_range
]
inline_diff_positions
=
position_mapping
[
inline_diff_range
]
.
flatten
# Turn the array of character positions into ranges
marker_ranges
=
collapse_ranges
(
inline_diff_positions
)
...
...
@@ -47,7 +47,19 @@ module Gitlab
rich_char
=
rich_line
[
rich_pos
]
end
mapping
[
raw_pos
]
=
rich_pos
# multi-char HTML entities in the rich line correspond to a single character in the raw line
if
rich_char
==
'&'
multichar_mapping
=
[
rich_pos
]
until
rich_char
==
';'
rich_pos
+=
1
multichar_mapping
<<
rich_pos
rich_char
=
rich_line
[
rich_pos
]
end
mapping
[
raw_pos
]
=
multichar_mapping
else
mapping
[
raw_pos
]
=
rich_pos
end
rich_pos
+=
1
end
...
...
lib/gitlab/diff/parser.rb
浏览文件 @
a010db5d
...
...
@@ -14,7 +14,7 @@ module Gitlab
@lines
.
each
do
|
line
|
next
if
filename?
(
line
)
full_line
=
html_escape
(
line
.
gsub
(
/\n/
,
''
)
)
full_line
=
line
.
gsub
(
/\n/
,
''
)
if
line
.
match
(
/^@@ -/
)
type
=
"match"
...
...
@@ -67,11 +67,6 @@ module Gitlab
nil
end
end
def
html_escape
(
str
)
replacements
=
{
'&'
=>
'&'
,
'>'
=>
'>'
,
'<'
=>
'<'
,
'"'
=>
'"'
,
"'"
=>
'''
}
str
.
gsub
(
/[&"'><]/
,
replacements
)
end
end
end
end
spec/lib/gitlab/diff/inline_diff_marker_spec.rb
浏览文件 @
a010db5d
...
...
@@ -2,14 +2,14 @@ require 'spec_helper'
describe
Gitlab
::
Diff
::
InlineDiffMarker
,
lib:
true
do
describe
'#inline_diffs'
do
let
(
:raw
)
{
"abc
def
"
}
let
(
:rich
)
{
%{<span class="abc">abc</span><span class="space"> </span><span class="def">
def
</span>}
}
let
(
:inline_diffs
)
{
[
2
..
4
]
}
let
(
:raw
)
{
"abc
'def'
"
}
let
(
:rich
)
{
%{<span class="abc">abc</span><span class="space"> </span><span class="def">
'def'
</span>}
}
let
(
:inline_diffs
)
{
[
2
..
5
]
}
let
(
:subject
)
{
Gitlab
::
Diff
::
InlineDiffMarker
.
new
(
raw
,
rich
).
mark
(
inline_diffs
)
}
it
'marks the inline diffs'
do
expect
(
subject
).
to
eq
(
%{<span class="abc">ab<span class='idiff'>c</span></span><span class="space"><span class='idiff'> </span></span><span class="def"><span class='idiff'>
d</span>ef
</span>}
)
expect
(
subject
).
to
eq
(
%{<span class="abc">ab<span class='idiff'>c</span></span><span class="space"><span class='idiff'> </span></span><span class="def"><span class='idiff'>
'd</span>ef'
</span>}
)
end
end
end
spec/lib/gitlab/diff/parser_spec.rb
浏览文件 @
a010db5d
...
...
@@ -86,7 +86,7 @@ eos
it
{
expect
(
line
.
type
).
to
eq
(
nil
)
}
it
{
expect
(
line
.
old_pos
).
to
eq
(
24
)
}
it
{
expect
(
line
.
new_pos
).
to
eq
(
31
)
}
it
{
expect
(
line
.
text
).
to
eq
(
' @cmd_output
<<
stderr.read'
)
}
it
{
expect
(
line
.
text
).
to
eq
(
' @cmd_output
<<
stderr.read'
)
}
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录