Kaydet (Commit) 7974269a authored tarafından Noel Grandin's avatar Noel Grandin

cid#1326733 Dm: Dubious method used

there is no point in re-decoding a Java String object, it is already
UTF-16

Change-Id: Iedc59d457422d32b306782f24cac9b6c2f6b04fe
üst ad280b67
...@@ -206,40 +206,36 @@ public class UnoUrl { ...@@ -206,40 +206,36 @@ public class UnoUrl {
private static String decodeUTF8(String s) private static String decodeUTF8(String s)
throws com.sun.star.lang.IllegalArgumentException { throws com.sun.star.lang.IllegalArgumentException {
if (!s.contains("%")) {
return s;
}
try { try {
if (s.contains("%")) { int length = s.length();
int length = s.length(); ByteBuffer bb = ByteBuffer.allocate(length);
ByteBuffer bb = ByteBuffer.allocate(length); for (int i = 0; i < length; i++) {
for (int i = 0; i < length; i++) { int ch = s.charAt(i);
int ch = s.charAt(i);
if (ch == '%') {
if (ch == '%') { if (i+3 > length)
if (i+3 > length) throw new com.sun.star.lang.IllegalArgumentException(
throw new com.sun.star.lang.IllegalArgumentException( "Incomplete trailing escape (%) pattern");
"Incomplete trailing escape (%) pattern"); try {
try { ch = Integer.parseInt(s.substring(i+1,i+3),16);
ch = Integer.parseInt(s.substring(i+1,i+3),16); } catch (NumberFormatException e) {
} catch (NumberFormatException e) { throw new com.sun.star.lang.IllegalArgumentException(e);
throw new com.sun.star.lang.IllegalArgumentException(e);
}
if (ch < 0)
throw new com.sun.star.lang.IllegalArgumentException(
"Illegal hex characters in escape (%) pattern - negative value");
i+=2;
} }
if (ch < 0)
bb.put((byte) (ch & 0xFF)); throw new com.sun.star.lang.IllegalArgumentException(
"Illegal hex characters in escape (%) pattern - negative value");
i+=2;
} }
byte[] bytes = new byte[bb.position()]; bb.put((byte) (ch & 0xFF));
System.arraycopy(bb.array(), 0, bytes, 0, bytes.length);
return new String(bytes, "UTF-8");
} else {
return new String(s.getBytes(), "UTF-8");
} }
byte[] bytes = new byte[bb.position()];
System.arraycopy(bb.array(), 0, bytes, 0, bytes.length);
return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new com.sun.star.lang.IllegalArgumentException(e, throw new com.sun.star.lang.IllegalArgumentException(e,
"Couldn't convert parameter string to UTF-8 string"); "Couldn't convert parameter string to UTF-8 string");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment