|
@@ -17,6 +17,8 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.http;
|
|
|
|
|
|
+import org.apache.commons.io.Charsets;
|
|
|
+
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
@@ -25,11 +27,11 @@ import java.io.OutputStream;
|
|
|
* This class is responsible for quoting HTML characters.
|
|
|
*/
|
|
|
public class HtmlQuoting {
|
|
|
- private static final byte[] ampBytes = "&".getBytes();
|
|
|
- private static final byte[] aposBytes = "'".getBytes();
|
|
|
- private static final byte[] gtBytes = ">".getBytes();
|
|
|
- private static final byte[] ltBytes = "<".getBytes();
|
|
|
- private static final byte[] quotBytes = """.getBytes();
|
|
|
+ private static final byte[] ampBytes = "&".getBytes(Charsets.UTF_8);
|
|
|
+ private static final byte[] aposBytes = "'".getBytes(Charsets.UTF_8);
|
|
|
+ private static final byte[] gtBytes = ">".getBytes(Charsets.UTF_8);
|
|
|
+ private static final byte[] ltBytes = "<".getBytes(Charsets.UTF_8);
|
|
|
+ private static final byte[] quotBytes = """.getBytes(Charsets.UTF_8);
|
|
|
|
|
|
/**
|
|
|
* Does the given string need to be quoted?
|
|
@@ -63,7 +65,7 @@ public class HtmlQuoting {
|
|
|
if (str == null) {
|
|
|
return false;
|
|
|
}
|
|
|
- byte[] bytes = str.getBytes();
|
|
|
+ byte[] bytes = str.getBytes(Charsets.UTF_8);
|
|
|
return needsQuoting(bytes, 0 , bytes.length);
|
|
|
}
|
|
|
|
|
@@ -98,15 +100,16 @@ public class HtmlQuoting {
|
|
|
if (item == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- byte[] bytes = item.getBytes();
|
|
|
+ byte[] bytes = item.getBytes(Charsets.UTF_8);
|
|
|
if (needsQuoting(bytes, 0, bytes.length)) {
|
|
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
try {
|
|
|
quoteHtmlChars(buffer, bytes, 0, bytes.length);
|
|
|
+ return buffer.toString("UTF-8");
|
|
|
} catch (IOException ioe) {
|
|
|
// Won't happen, since it is a bytearrayoutputstream
|
|
|
+ return null;
|
|
|
}
|
|
|
- return buffer.toString();
|
|
|
} else {
|
|
|
return item;
|
|
|
}
|