From b429b47cf98881d9335ca41c93afc5f7fe4f7705 Mon Sep 17 00:00:00 2001 From: Alex Clayton Date: Mon, 13 Jul 2015 15:24:33 +0100 Subject: 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 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; - } } } -- cgit v0.10.2-6-g49f6