Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/git/GitChangeLogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -33,7 +34,7 @@ public GitChangeSetList parse(AbstractBuild build, File changelogFile)

// Parse the log file into GitChangeSet items - each one is a commit

BufferedReader rdr = new BufferedReader(new FileReader(changelogFile));
BufferedReader rdr = new BufferedReader(new InputStreamReader(new FileInputStream(changelogFile), "utf-8"));

try {
String line;
Expand Down
41 changes: 33 additions & 8 deletions src/test/java/hudson/plugins/git/GitChangeLogParserTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package hudson.plugins.git;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

import org.jvnet.hudson.test.HudsonTestCase;

Expand All @@ -10,20 +12,31 @@
*/
public class GitChangeLogParserTest extends HudsonTestCase {

private File createChangeLogFile(String firstLine, String... restLines) throws Exception {
File log = File.createTempFile(getClass().getName(), ".tmp");
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(log), "utf-8"));
writer.write(firstLine);
for (String line : restLines) {
writer.write("\n" + line);
}
writer.close();
return log;
}

/**
* Test duplicate changes filtered from parsed change set list.
*
* @throws Exception
*/
public void testDuplicatesFiltered() throws Exception {
GitChangeLogParser parser = new GitChangeLogParser(true);
File log = File.createTempFile(getClass().getName(), ".tmp");
FileWriter writer = new FileWriter(log);
writer.write("commit 123abc456def\n");
writer.write(" first message\n");
writer.write("commit 123abc456def\n");
writer.write(" second message");
writer.close();
File log = createChangeLogFile(
"commit 123abc456def",
" first message",
"commit 123abc456def",
" second message"
);

GitChangeSetList list = parser.parse(null, log);
assertNotNull(list);
assertNotNull(list.getLogs());
Expand All @@ -33,4 +46,16 @@ public void testDuplicatesFiltered() throws Exception {
assertEquals("123abc456def", first.getId());
assertEquals("first message", first.getMsg());
}

public void testCharacterCorruptionProblem() throws Exception {
GitChangeLogParser parser = new GitChangeLogParser(true);
File log = createChangeLogFile(
"commit 123abc456def",
" 日本語"
);

GitChangeSetList list = parser.parse(null, log);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test would pass on a typical Linux machine (or anything else using UTF-8 by default) without the source code change, meaning when run on ci.jenkins-ci.org or the like it would not defend against regressions. To make it a stronger test you would need to call e.g. System.setProperty("file.encoding", "ISO-8859-1") very early in test VM startup, perhaps in a static block; or even pass this system property in Surefire configuration to make sure it is set from the start.

GitChangeSet changeSet = list.getLogs().get(0);
assertEquals("日本語", changeSet.getMsg());
}
}