harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r605300 - in /harmony/enhanced/classlib/trunk/modules/text/src: main/java/java/text/MessageFormat.java test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
Date Tue, 18 Dec 2007 19:06:45 GMT
Author: apetrenko
Date: Tue Dec 18 11:06:44 2007
New Revision: 605300

URL: http://svn.apache.org/viewvc?rev=605300&view=rev
Log:
Patch for HARMONY-5323 "[classlib][text][Tomcat] MessageFormat.format 
can not format messages with more then 10 variables"

Modified:
    harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java
    harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java

Modified: harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java?rev=605300&r1=605299&r2=605300&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/MessageFormat.java
Tue Dec 18 11:06:44 2007
@@ -102,15 +102,31 @@
         Vector<Format> localFormats = new Vector<Format>();
         while (position.getIndex() < length) {
             if (Format.upTo(template, position, buffer, '{')) {
-                byte arg;
+                int arg = 0;
                 int offset = position.getIndex();
-                if (offset >= length
-                        || (arg = (byte) Character.digit(template
-                                .charAt(offset++), 10)) == -1) {
+                if (offset >= length) {
                     // text.19=Invalid argument number
                     throw new IllegalArgumentException(Messages
                             .getString("text.19")); //$NON-NLS-1$
                 }
+                // Get argument number
+                char ch;
+                while ((ch = template.charAt(offset++)) != '}' && ch != ',') {
+                    if (ch < '0' && ch > '9') {
+                        // text.19=Invalid argument number
+                        throw new IllegalArgumentException(Messages
+                            .getString("text.19")); //$NON-NLS-1$
+                    }
+                    
+                    arg = arg * 10 + (ch - '0');
+                    
+                    if (arg < 0 || offset >= length) {
+                        // text.19=Invalid argument number
+                        throw new IllegalArgumentException(Messages
+                            .getString("text.19")); //$NON-NLS-1$
+                    }
+                }
+                offset--;
                 position.setIndex(offset);
                 localFormats.addElement(parseVariable(template, position));
                 if (argCount >= args.length) {

Modified: harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java?rev=605300&r1=605299&r2=605300&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
Tue Dec 18 11:06:44 2007
@@ -765,4 +765,12 @@
         assertEquals(etalon, obj.format(new Object[]{new Date((new Date().getTime()))}));

     } 
 
+    public void testHARMONY5323() { 
+    	Object []messageArgs = new Object[11];
+    	for (int i = 0; i < messageArgs.length; i++)
+    		messageArgs[i] = "dumb"+i;
+    	    	
+		String res = MessageFormat.format("bgcolor=\"{10}\"", messageArgs);
+        assertEquals(res, "bgcolor=\"dumb10\"");
+    } 
 }



Mime
View raw message