harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r617124 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Properties.java main/java/org/apache/harmony/luni/internal/nls/messages.properties test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
Date Thu, 31 Jan 2008 13:34:08 GMT
Author: tellison
Date: Thu Jan 31 05:33:55 2008
New Revision: 617124

URL: http://svn.apache.org/viewvc?rev=617124&view=rev
Log:
Fix for HARMONY-5414 (java.util.Properties.load() decodes invalid unicode sequences)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java?rev=617124&r1=617123&r2=617124&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java Thu
Jan 31 05:33:55 2008
@@ -43,6 +43,7 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
+import org.apache.harmony.luni.internal.nls.Messages;
 import org.apache.harmony.luni.util.PriviAction;
 
 /**
@@ -280,6 +281,9 @@
                     if (++count < 4) {
                         continue;
                     }
+                } else if (count <= 4) {
+                    // luni.09=Invalid Unicode sequence: illegal character
+                    throw new IllegalArgumentException(Messages.getString("luni.09"));
                 }
                 mode = NONE;
                 buf[offset++] = (char) unicode;
@@ -398,12 +402,21 @@
             }
             buf[offset++] = nextChar;
         }
+        if (mode == UNICODE && count <= 4) {
+            // luni.08=Invalid Unicode sequence: expected format \\uxxxx
+            throw new IllegalArgumentException(Messages.getString("luni.08"));
+        }
         if (keyLength == -1 && offset > 0) {
             keyLength = offset;
         }
         if (keyLength >= 0) {
             String temp = new String(buf, 0, offset);
-            put(temp.substring(0, keyLength), temp.substring(keyLength));
+            String key = temp.substring(0, keyLength);
+            String value = temp.substring(keyLength);
+            if (mode == SLASH) {
+                value += "\u0000";
+            }
+            put(key, value);
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/nls/messages.properties?rev=617124&r1=617123&r2=617124&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/nls/messages.properties
Thu Jan 31 05:33:55 2008
@@ -22,3 +22,5 @@
 luni.05=Attempt to insert {0} element into collection with element type {1}
 luni.06=The string argument is null
 luni.07=The stream is corrupted
+luni.08=Invalid Unicode sequence: expected format \\uxxxx
+luni.09=Invalid Unicode sequence: illegal character

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java?rev=617124&r1=617123&r2=617124&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
Thu Jan 31 05:33:55 2008
@@ -177,6 +177,44 @@
                         .getBytes("ISO8859_1")));
         assertEquals("Failed to load when last line contains a comment", "1",
                 prop.get("fred"));
+
+        // Regression tests for HARMONY-5414
+        prop = new Properties();
+        prop.load(new ByteArrayInputStream("a=\\u1234z".getBytes()));
+
+        prop = new Properties();
+        try {
+            prop.load(new ByteArrayInputStream("a=\\u123".getBytes()));
+            fail("Expected IllegalArgumentException due to invalid Unicode sequence");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+
+        prop = new Properties();
+        try {
+            prop.load(new ByteArrayInputStream("a=\\u123z".getBytes()));
+            fail("Expected IllegalArgumentException due to invalid unicode sequence");
+        } catch (IllegalArgumentException expected) {
+            // Expected
+        }
+
+        prop = new Properties();
+        Properties expected = new Properties();
+        expected.put("a", "\u0000");
+        prop.load(new ByteArrayInputStream("a=\\".getBytes()));
+        assertEquals("Failed to read trailing slash value", expected, prop);
+
+        prop = new Properties();
+        expected = new Properties();
+        expected.put("a", "\u1234\u0000");
+        prop.load(new ByteArrayInputStream("a=\\u1234\\".getBytes()));
+        assertEquals("Failed to read trailing slash value #2", expected, prop);
+
+        prop = new Properties();
+        expected = new Properties();
+        expected.put("a", "q");
+        prop.load(new ByteArrayInputStream("a=\\q".getBytes()));
+        assertEquals("Failed to read slash value #3", expected, prop);
     }
 
     /**



Mime
View raw message