Fix apply patch which did not work with non-ascii characters
Bug: 483943 Change-Id: If28f64053d20ab1bee54245f223e952dc2fe392c Signed-off-by: XinTong Wang <xintong@ca.ibm.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
be8c525fa0
commit
770d36c8ba
|
@ -144,10 +144,10 @@ protected void deleteTrashFile(final String name) throws IOException {
|
||||||
|
|
||||||
protected static void checkFile(File f, final String checkData)
|
protected static void checkFile(File f, final String checkData)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Reader r = new InputStreamReader(new FileInputStream(f), "ISO-8859-1");
|
Reader r = new InputStreamReader(new FileInputStream(f), "UTF-8");
|
||||||
try {
|
try {
|
||||||
char[] data = new char[(int) f.length()];
|
char[] data = new char[checkData.length()];
|
||||||
if (f.length() != r.read(data))
|
if (checkData.length() != r.read(data))
|
||||||
throw new IOException("Internal error reading file data from "+f);
|
throw new IOException("Internal error reading file data from "+f);
|
||||||
assertEquals(checkData, new String(data));
|
assertEquals(checkData, new String(data));
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -186,6 +186,55 @@ public void testModifyNL1() throws Exception {
|
||||||
b.getString(0, b.size(), false));
|
b.getString(0, b.size(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonASCII() throws Exception {
|
||||||
|
ApplyResult result = init("NonASCII");
|
||||||
|
assertEquals(1, result.getUpdatedFiles().size());
|
||||||
|
assertEquals(new File(db.getWorkTree(), "NonASCII"),
|
||||||
|
result.getUpdatedFiles().get(0));
|
||||||
|
checkFile(new File(db.getWorkTree(), "NonASCII"),
|
||||||
|
b.getString(0, b.size(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonASCII2() throws Exception {
|
||||||
|
ApplyResult result = init("NonASCII2");
|
||||||
|
assertEquals(1, result.getUpdatedFiles().size());
|
||||||
|
assertEquals(new File(db.getWorkTree(), "NonASCII2"),
|
||||||
|
result.getUpdatedFiles().get(0));
|
||||||
|
checkFile(new File(db.getWorkTree(), "NonASCII2"),
|
||||||
|
b.getString(0, b.size(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonASCIIAdd() throws Exception {
|
||||||
|
ApplyResult result = init("NonASCIIAdd");
|
||||||
|
assertEquals(1, result.getUpdatedFiles().size());
|
||||||
|
assertEquals(new File(db.getWorkTree(), "NonASCIIAdd"),
|
||||||
|
result.getUpdatedFiles().get(0));
|
||||||
|
checkFile(new File(db.getWorkTree(), "NonASCIIAdd"),
|
||||||
|
b.getString(0, b.size(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonASCIIAdd2() throws Exception {
|
||||||
|
ApplyResult result = init("NonASCIIAdd2", false, true);
|
||||||
|
assertEquals(1, result.getUpdatedFiles().size());
|
||||||
|
assertEquals(new File(db.getWorkTree(), "NonASCIIAdd2"),
|
||||||
|
result.getUpdatedFiles().get(0));
|
||||||
|
checkFile(new File(db.getWorkTree(), "NonASCIIAdd2"),
|
||||||
|
b.getString(0, b.size(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonASCIIDel() throws Exception {
|
||||||
|
ApplyResult result = init("NonASCIIDel", true, false);
|
||||||
|
assertEquals(1, result.getUpdatedFiles().size());
|
||||||
|
assertEquals(new File(db.getWorkTree(), "NonASCIIDel"),
|
||||||
|
result.getUpdatedFiles().get(0));
|
||||||
|
assertFalse(new File(db.getWorkTree(), "NonASCIIDel").exists());
|
||||||
|
}
|
||||||
|
|
||||||
private static byte[] readFile(final String patchFile) throws IOException {
|
private static byte[] readFile(final String patchFile) throws IOException {
|
||||||
final InputStream in = getTestResource(patchFile);
|
final InputStream in = getTestResource(patchFile);
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
|
|
|
@ -201,10 +201,12 @@ private void apply(File f, FileHeader fh)
|
||||||
oldLines.add(rt.getString(i));
|
oldLines.add(rt.getString(i));
|
||||||
List<String> newLines = new ArrayList<String>(oldLines);
|
List<String> newLines = new ArrayList<String>(oldLines);
|
||||||
for (HunkHeader hh : fh.getHunks()) {
|
for (HunkHeader hh : fh.getHunks()) {
|
||||||
StringBuilder hunk = new StringBuilder();
|
|
||||||
for (int j = hh.getStartOffset(); j < hh.getEndOffset(); j++)
|
byte[] b = new byte[hh.getEndOffset() - hh.getStartOffset()];
|
||||||
hunk.append((char) hh.getBuffer()[j]);
|
System.arraycopy(hh.getBuffer(), hh.getStartOffset(), b, 0,
|
||||||
RawText hrt = new RawText(hunk.toString().getBytes());
|
b.length);
|
||||||
|
RawText hrt = new RawText(b);
|
||||||
|
|
||||||
List<String> hunkLines = new ArrayList<String>(hrt.size());
|
List<String> hunkLines = new ArrayList<String>(hrt.size());
|
||||||
for (int i = 0; i < hrt.size(); i++)
|
for (int i = 0; i < hrt.size(); i++)
|
||||||
hunkLines.add(hrt.getString(i));
|
hunkLines.add(hrt.getString(i));
|
||||||
|
|
Loading…
Reference in New Issue