Skip to content

Commit 3d8046d

Browse files
author
Peter Degen-Portnoy
committed
Merge pull request #19 from notalex/OTWO-3206
OTWO-3206: Fix utf-8 encoding issues for svn and git
2 parents a2e4675 + 8dd490b commit 3d8046d

File tree

14 files changed

+119
-11
lines changed

14 files changed

+119
-11
lines changed

lib/scm/adapters/git/commits.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def each_commit(opts={})
5050

5151
# Returns a single commit, including its diffs
5252
def verbose_commit(token)
53-
c = Scm::Parsers::GitStyledParser.parse(run("cd '#{url}' && #{Scm::Parsers::GitStyledParser.whatchanged} #{token}")).first
53+
c = Scm::Parsers::GitStyledParser.parse(run("cd '#{url}' && #{Scm::Parsers::GitStyledParser.whatchanged} #{token} | #{ string_encoder }")).first
5454
fixup_null_merge(c)
5555
end
5656

lib/scm/adapters/svn/commits.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def verbose_commit(rev)
144144

145145
def log(opts={})
146146
after = (opts[:after] || 0).to_i
147-
run "svn log --trust-server-cert --non-interactive --xml --stop-on-copy -r #{after.to_i + 1}:#{final_token || 'HEAD'} '#{SvnAdapter.uri_encode(File.join(self.root, self.branch_name.to_s))}@#{final_token || 'HEAD'}' #{opt_auth}"
147+
run "svn log --trust-server-cert --non-interactive --xml --stop-on-copy -r #{after.to_i + 1}:#{final_token || 'HEAD'} '#{SvnAdapter.uri_encode(File.join(self.root, self.branch_name.to_s))}@#{final_token || 'HEAD'}' #{opt_auth} | #{ string_encoder }"
148148
end
149149

150150
def open_log_file(opts={})
@@ -154,7 +154,7 @@ def open_log_file(opts={})
154154
# As a time optimization, just create an empty file rather than fetch a log we know will be empty.
155155
File.open(log_filename, 'w') { |f| f.puts '<?xml version="1.0"?>' }
156156
else
157-
run "svn log --trust-server-cert --non-interactive --xml --stop-on-copy -r #{after + 1}:#{final_token || 'HEAD'} '#{SvnAdapter.uri_encode(File.join(self.root, self.branch_name))}@#{final_token || 'HEAD'}' #{opt_auth} > #{log_filename}"
157+
run "svn log --trust-server-cert --non-interactive --xml --stop-on-copy -r #{after + 1}:#{final_token || 'HEAD'} '#{SvnAdapter.uri_encode(File.join(self.root, self.branch_name))}@#{final_token || 'HEAD'}' #{opt_auth} | #{ string_encoder } > #{log_filename}"
158158
end
159159
File.open(log_filename, 'r') { |io| yield io }
160160
ensure
@@ -168,7 +168,7 @@ def log_filename
168168

169169
# Returns one commit with the exact revision number provided
170170
def single_revision_xml(revision)
171-
run "svn log --trust-server-cert --non-interactive --verbose --xml --stop-on-copy -r #{revision} --limit 1 #{opt_auth} '#{SvnAdapter.uri_encode(File.join(self.root, self.branch_name))}@#{revision}'"
171+
run "svn log --trust-server-cert --non-interactive --verbose --xml --stop-on-copy -r #{revision} --limit 1 #{opt_auth} '#{SvnAdapter.uri_encode(File.join(self.root, self.branch_name))}@#{revision}' | #{ string_encoder }"
172172
end
173173

174174
# Recurses the entire repository and returns an array of file names.

lib/scm/adapters/svn/head.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def head
1111
def parents(commit)
1212
# Subversion doesn't have an actual "parent" command, so get
1313
# a log for this commit and the one preceding it, and keep only the preceding.
14-
log = run "svn log --trust-server-cert --non-interactive --verbose --xml --stop-on-copy -r #{commit.token}:1 --limit 2 '#{SvnAdapter.uri_encode(self.url)}' #{opt_auth}"
14+
log = run "svn log --trust-server-cert --non-interactive --verbose --xml --stop-on-copy -r #{commit.token}:1 --limit 2 '#{SvnAdapter.uri_encode(self.url)}' #{opt_auth} | #{ string_encoder }"
1515
[deepen_commit(strip_commit_branch(Scm::Parsers::SvnXmlParser.parse(log).last))]
1616
end
1717
end

lib/scm/adapters/svn_chain/chain.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def first_commit(after=0)
7979
# Returns the first commit with a revision number greater than the provided revision number
8080
def next_revision_xml(after=0)
8181
return "<?xml?>" if after.to_i >= head_token
82-
run "svn log --trust-server-cert --non-interactive --verbose --xml --stop-on-copy -r #{after.to_i+1}:#{final_token || 'HEAD'} --limit 1 #{opt_auth} '#{SvnAdapter.uri_encode(File.join(self.root, self.branch_name))}@#{final_token || 'HEAD'}'"
82+
run "svn log --trust-server-cert --non-interactive --verbose --xml --stop-on-copy -r #{after.to_i+1}:#{final_token || 'HEAD'} --limit 1 #{opt_auth} '#{SvnAdapter.uri_encode(File.join(self.root, self.branch_name))}@#{final_token || 'HEAD'}' | #{ string_encoder }"
8383
end
8484

8585
# If the passed diff represents the wholesale movement of the entire

test/bin/svn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /usr/bin/env bash
2+
# This is for use with tests dealing with invalid encodings in svn log.
3+
# This script returns a sample svn xml log with some non utf-8 characters.
4+
5+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
7+
cat $DIR/../data/svn_with_invalid_encoding.log
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<log>
3+
<logentry
4+
revision="4">
5+
<author>cartman</author>
6+
<date>2000-08-29T18:45:43.000000Z</date>
7+
<msg>Ample parking day or night, people spouting: "Howdy, neighbor!"
8+
</msg>
9+
</logentry>
10+
<logentry
11+
revision="3">
12+
<author>primus</author>
13+
<date>2002-07-11T14:27:53.000000Z</date>
14+
<msg>I'm goin' down to South Park, gonna leave my woes behind.
15+
16+
Thanks to Kenny Möller
17+
</msg>
18+
</logentry>
19+
<logentry
20+
revision="2">
21+
<author>stan</author>
22+
<date>2002-07-11T18:19:49.000000Z</date>
23+
<msg>Friendly faces everywhere, humble folks without temptation
24+
</msg>
25+
</logentry>
26+
<logentry
27+
revision="1">
28+
<author>primus</author>
29+
<date>2002-07-12T08:14:23.000000Z</date>
30+
<msg>I'm goin' down to South Park, gonna have myself a time.
31+
</msg>
32+
</logentry>
33+
</log>
689 Bytes
Binary file not shown.

test/test_helper.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ def with_repository(type, name)
6060
end
6161
end
6262

63+
# We are unable to add a commit message with non utf8 characters using svn 1.6 & above.
64+
# In order to emulate encoding issues, we use a custom svn executable that returns
65+
# an xml log with invalid characters in it.
66+
# We prepend our custom svn's location to $PATH to make it available during our tests.
67+
def with_invalid_encoded_svn_repository
68+
with_repository(Scm::Adapters::SvnChainAdapter, 'svn_with_invalid_encoding') do |svn|
69+
original_env_path = ENV['PATH']
70+
custom_svn_path = File.expand_path('../bin/', __FILE__)
71+
ENV['PATH'] = custom_svn_path + ':' + ENV['PATH']
72+
73+
yield svn
74+
75+
ENV['PATH'] = original_env_path
76+
end
77+
end
78+
6379
def with_svn_repository(name, branch_name='')
6480
with_repository(Scm::Adapters::SvnAdapter, name) do |svn|
6581
svn.branch_name = branch_name

test/unit/git_commits_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ def test_log_encoding
133133
end
134134
end
135135

136+
def test_verbose_commits_valid_encoding
137+
with_git_repository('git_with_invalid_encoding') do |git|
138+
assert_equal true,
139+
git.verbose_commit('8d03f4ea64fcd10966fb3773a212b141ada619e1').message.valid_encoding?
140+
end
141+
end
142+
136143
def test_open_log_file_encoding
137144
with_git_repository('git_with_invalid_encoding') do |git|
138145
git.open_log_file do |io|

test/unit/git_head_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ def test_head_and_parents
1515
end
1616
end
1717

18+
def test_head_token
19+
with_git_repository('git_with_invalid_encoding') do |git|
20+
assert_nothing_raised do
21+
git.head_token
22+
end
23+
end
24+
end
1825
end
1926
end

0 commit comments

Comments
 (0)