summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2015-07-13 14:24:33 (GMT)
committerNick Hudson <nick.hudson@isode.com>2015-07-20 15:15:40 (GMT)
commitb429b47cf98881d9335ca41c93afc5f7fe4f7705 (patch)
tree8680114d2d298efd429789049facabe8f030b090
parentde14a6ae530f450dc89493d0bc2f3d1100e4eeba (diff)
downloadstroke-b429b47cf98881d9335ca41c93afc5f7fe4f7705.zip
stroke-b429b47cf98881d9335ca41c93afc5f7fe4f7705.tar.bz2
Add StringIndexOutOfBounds catch to IDNA
When run with java 7 class IDNA.getEncoded was throwing a StringIndexOutOfBounds exception if it was passed a String begining with '.isode'. This has the knock on effect of some of one of the isode MLC tests failing. This was caused by IDN.toAscii throwing the exception, when it should only thrown IllegalArgumentException. Java 7 is no longer supported so I can't raise a bug for this, a fix for stroke is easy though, just add the StringIndexOutOfBoundException to the catch block. Test-information: Ran the tests that were failing in eclipse on my machine (which runs java 7) tests now all passed correctly. Sanity test that tests still passed when run on command line against java 8. Ran the Stroke JUnit test against the code. Tests all passed when using latest version of java 7 (7_79) and when using java 8. Change-Id: Ifc9c830be7a0e5c9e5f2330a6782eff2401f18cb
-rw-r--r--src/com/isode/stroke/idn/IDNA.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/com/isode/stroke/idn/IDNA.java b/src/com/isode/stroke/idn/IDNA.java
index e3b86dd..653a2d2 100644
--- a/src/com/isode/stroke/idn/IDNA.java
+++ b/src/com/isode/stroke/idn/IDNA.java
@@ -4,7 +4,7 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
/*
- * Copyright (c) 2011, Isode Limited, London, England.
+ * Copyright (c) 2011-2015, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.idn;
@@ -13,11 +13,16 @@ import java.net.IDN;
public class IDNA {
public static String getEncoded(String s) {
- try {
- return IDN.toASCII(s, IDN.USE_STD3_ASCII_RULES);
+ try {
+ return IDN.toASCII(s, IDN.USE_STD3_ASCII_RULES);
+ }
+ catch (IllegalArgumentException e) {
+ return null;
+ }
+ catch (StringIndexOutOfBoundsException e) {
+ // In java 7 IDN.toASCII sometimes throws StringIndexOutOfBoundException
+ // (instead of IllegalArgumentException)
+ return null;
}
- catch (IllegalArgumentException e) {
- return null;
- }
}
}