abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ckopp...@apache.org
Subject svn commit: r1042481 - in /abdera/java/trunk/dependencies/i18n/src: main/java/org/apache/abdera/i18n/iri/ main/java/org/apache/abdera/i18n/text/ test/java/org/apache/abdera/i18n/test/iri/
Date Sun, 05 Dec 2010 22:51:21 GMT
Author: ckoppelt
Date: Sun Dec  5 22:51:21 2010
New Revision: 1042481

URL: http://svn.apache.org/viewvc?rev=1042481&view=rev
Log:
fix for ABDERA-258

Removed:
    abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestSuite.java
Modified:
    abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IDNA.java
    abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java
    abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/CharUtils.java
    abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIRI.java

Modified: abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IDNA.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IDNA.java?rev=1042481&r1=1042480&r2=1042481&view=diff
==============================================================================
--- abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IDNA.java
(original)
+++ abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IDNA.java
Sun Dec  5 22:51:21 2010
@@ -22,9 +22,9 @@ import java.io.Serializable;
 import java.net.UnknownHostException;
 
 import org.apache.abdera.i18n.text.CharUtils;
+import org.apache.abdera.i18n.text.CharUtils.Profile;
 import org.apache.abdera.i18n.text.Nameprep;
 import org.apache.abdera.i18n.text.Punycode;
-import org.apache.abdera.i18n.text.CharUtils.Profile;
 
 /**
  * Provides an Internationized Domain Name implementation
@@ -94,10 +94,12 @@ public final class IDNA implements Seria
 
     public static String toASCII(String regname) {
         try {
-            if (regname == null)
+            if (regname == null){
                 return null;
-            if (regname.length() == 0)
+            }
+            if (regname.length() == 0){
                 return regname;
+            }
             String[] labels = regname.split("\\\u002E");
             StringBuilder buf = new StringBuilder();
             for (String label : labels) {

Modified: abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java?rev=1042481&r1=1042480&r2=1042481&view=diff
==============================================================================
--- abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java
(original)
+++ abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/iri/IRI.java
Sun Dec  5 22:51:21 2010
@@ -25,11 +25,11 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.abdera.i18n.text.CharUtils;
+import org.apache.abdera.i18n.text.CharUtils.Profile;
 import org.apache.abdera.i18n.text.InvalidCharacterException;
 import org.apache.abdera.i18n.text.Nameprep;
 import org.apache.abdera.i18n.text.Normalizer;
 import org.apache.abdera.i18n.text.UrlEncoding;
-import org.apache.abdera.i18n.text.CharUtils.Profile;
 import org.apache.abdera.i18n.text.data.UnicodeCharacterDatabase;
 
 public final class IRI implements Serializable, Cloneable {
@@ -121,7 +121,11 @@ public final class IRI implements Serial
     }
 
     private void init() {
-        a_host = IDNA.toASCII(host);
+        if (host != null && host.startsWith("[")) {
+            a_host = host;
+        } else {
+            a_host = IDNA.toASCII(host);
+        }
         a_fragment = UrlEncoding.encode(fragment, Profile.FRAGMENT.filter());
         a_path = UrlEncoding.encode(path, Profile.PATH.filter());
         a_query = UrlEncoding.encode(query, Profile.QUERY.filter(), Profile.PATH.filter());
@@ -312,7 +316,8 @@ public final class IRI implements Serial
         try {
             return super.clone();
         } catch (CloneNotSupportedException e) {
-            return new IRI(toString()); // not going to happen, but we have to catch it
+            return new IRI(toString()); // not going to happen, but we have to
+                                        // catch it
         }
     }
 
@@ -544,7 +549,7 @@ public final class IRI implements Serial
             }
             try {
                 CharUtils.verify(userinfo, Profile.IUSERINFO);
-                CharUtils.verify(host, Profile.IREGNAME);
+                CharUtils.verify(host, Profile.IHOST);
             } catch (InvalidCharacterException e) {
                 throw new IRISyntaxException(e);
             }

Modified: abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/CharUtils.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/CharUtils.java?rev=1042481&r1=1042480&r2=1042481&view=diff
==============================================================================
--- abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/CharUtils.java
(original)
+++ abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/text/CharUtils.java
Sun Dec  5 22:51:21 2010
@@ -413,6 +413,10 @@ public final class CharUtils {
     public static boolean isAlphaDigit(int codepoint) {
         return isDigit(codepoint) || isAlpha(codepoint);
     }
+    
+    public static boolean isHex (int codepoint){
+        return isDigit(codepoint) || CharUtils.inRange(codepoint, 'a', 'f') || CharUtils.inRange(codepoint,
'A', 'F');
+    }
 
     /**
      * True if the codepoint is a bidi control character
@@ -538,6 +542,10 @@ public final class CharUtils {
             public boolean accept(int codepoint) {
                 return !is_iregname(codepoint);
             }
+        }), IHOST (new Filter(){
+            public boolean accept(int codepoint){
+                return !is_ihost(codepoint);
+            }
         }), IPRIVATE(new Filter() {
             public boolean accept(int codepoint) {
                 return !is_iprivate(codepoint);
@@ -764,6 +772,16 @@ public final class CharUtils {
             || codepoint == '='
             || codepoint == '"';
     }
+    
+    public static boolean is_ipliteral (int codepoint){
+        return isHex(codepoint) || codepoint==':' 
+            || codepoint =='[' 
+            || codepoint==']';
+    }
+    
+    public static boolean is_ihost (int codepoint){
+        return is_iregname(codepoint) || is_ipliteral(codepoint);
+    }
 
     public static boolean is_regname(int codepoint) {
         return isUnreserved(codepoint) || codepoint == '!'

Modified: abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIRI.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIRI.java?rev=1042481&r1=1042480&r2=1042481&view=diff
==============================================================================
--- abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIRI.java
(original)
+++ abdera/java/trunk/dependencies/i18n/src/test/java/org/apache/abdera/i18n/test/iri/TestIRI.java
Sun Dec  5 22:51:21 2010
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.assertFalse;
 
 import java.net.URI;
+import java.net.URISyntaxException;
 
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.i18n.text.Normalizer;
@@ -36,6 +37,24 @@ public class TestIRI extends TestBase {
         assertEquals("http://validator.w3.org/check?uri=http%3A%2F%2Fr%C3%A9sum%C3%A9.example.org",
iri.toURI()
             .toString());
     }
+    
+    @Test
+    public void testIpv4() throws URISyntaxException{
+        IRI iri = new IRI("http://127.0.0.1");
+        assertEquals("http://127.0.0.1", iri.toURI().toString());
+    }
+    
+    @Test
+    public void testIpv6() throws URISyntaxException{
+        IRI iri = new IRI("http://[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]");
+        assertEquals("http://[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]", iri.toURI().toString());
+    }
+    
+    @Test(expected=URISyntaxException.class)
+    public void testIpv6Invalid() throws URISyntaxException{
+        IRI iri = new IRI("http://[2001:0db8:85a3:08d3:1319:8a2e:0370:734o]");
+        iri.toURI().toString();
+    }
 
     @Test
     public void testFile() throws Exception {



Mime
View raw message