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
Boxiang Sun
gitlab-ce
Commits
c36adb98
Commit
c36adb98
authored
Aug 11, 2015
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug where backslashes in inline diffs could be dropped
Closes #2253
parent
cb6ad67f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
2 deletions
+45
-2
CHANGELOG
CHANGELOG
+1
-0
lib/gitlab/inline_diff.rb
lib/gitlab/inline_diff.rb
+5
-2
spec/lib/gitlab/diff/inline_diff_spec.rb
spec/lib/gitlab/diff/inline_diff_spec.rb
+39
-0
No files found.
CHANGELOG
View file @
c36adb98
Please view this file on the master branch, on stable branches it's out of date.
Please view this file on the master branch, on stable branches it's out of date.
v 7.14.0 (unreleased)
v 7.14.0 (unreleased)
- Fix bug where backslashes in inline diffs could be dropped (Stan Hu)
- Disable turbolinks when linking to Bitbucket import status (Stan Hu)
- Disable turbolinks when linking to Bitbucket import status (Stan Hu)
- Fix broken code import and display error messages if something went wrong with creating project (Stan Hu)
- Fix broken code import and display error messages if something went wrong with creating project (Stan Hu)
- Fix corrupted binary files when using API files endpoint (Stan Hu)
- Fix corrupted binary files when using API files endpoint (Stan Hu)
...
...
lib/gitlab/inline_diff.rb
View file @
c36adb98
...
@@ -46,8 +46,11 @@ module Gitlab
...
@@ -46,8 +46,11 @@ module Gitlab
end
end
last_the_same_symbols
+=
1
last_the_same_symbols
+=
1
last_token
=
first_line
[
last_the_same_symbols
..-
1
]
last_token
=
first_line
[
last_the_same_symbols
..-
1
]
diff_arr
[
index
+
1
].
sub!
(
/
#{
Regexp
.
escape
(
last_token
)
}
$/
,
FINISH
+
last_token
)
# This is tricky: escape backslashes so that `sub` doesn't interpret them
diff_arr
[
index
+
2
].
sub!
(
/
#{
Regexp
.
escape
(
last_token
)
}
$/
,
FINISH
+
last_token
)
# as backreferences. Regexp.escape does NOT do the right thing.
replace_token
=
FINISH
+
last_token
.
gsub
(
/\\/
,
'\&\&'
)
diff_arr
[
index
+
1
].
sub!
(
/
#{
Regexp
.
escape
(
last_token
)
}
$/
,
replace_token
)
diff_arr
[
index
+
2
].
sub!
(
/
#{
Regexp
.
escape
(
last_token
)
}
$/
,
replace_token
)
end
end
diff_arr
diff_arr
end
end
...
...
spec/lib/gitlab/diff/inline_diff_spec.rb
0 → 100644
View file @
c36adb98
require
'spec_helper'
describe
Gitlab
::
InlineDiff
do
describe
'#processing'
do
let
(
:diff
)
do
<<
eos
--- a/test.rb
+++ b/test.rb
@@ -1,6 +1,6 @@
class Test
def cleanup_string(input)
return nil if input.nil?
- input.sub(/[
\\
r
\\
n].+/,'').sub(/
\\\\
[rn].+/, '').strip
+ input.to_s.sub(/[
\\
r
\\
n].+/,'').sub(/
\\\\
[rn].+/, '').strip
end
end
eos
end
let
(
:expected
)
do
[
"--- a/test.rb
\n
"
,
"+++ b/test.rb
\n
"
,
"@@ -1,6 +1,6 @@
\n
"
,
" class Test
\n
"
,
" def cleanup_string(input)
\n
"
,
" return nil if input.nil?
\n
"
,
"- input.#!idiff-start!##!idiff-finish!#sub(/[
\\
r
\\
n].+/,'').sub(/
\\\\
[rn].+/, '').strip
\n
"
,
"+ input.#!idiff-start!#to_s.#!idiff-finish!#sub(/[
\\
r
\\
n].+/,'').sub(/
\\\\
[rn].+/, '').strip
\n
"
,
" end
\n
"
,
" end
\n
"
]
end
let
(
:subject
)
{
Gitlab
::
InlineDiff
.
processing
(
diff
.
lines
)
}
it
'should retain backslashes'
do
expect
(
subject
).
to
eq
(
expected
)
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