You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2011/09/09 17:15:21 UTC
svn commit: r1167242 - in
/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src:
main/java/org/apache/myfaces/trinidad/util/FastMessageFormat.java
test/java/org/apache/myfaces/trinidad/util/FastMessageFormatTest.java
Author: sobryan
Date: Fri Sep 9 15:15:20 2011
New Revision: 1167242
URL: http://svn.apache.org/viewvc?rev=1167242&view=rev
Log:
TRINIDAD-2116 - ResourceBundles Strings containing doubled single quotes are not properly formatted by FastMessageFormat on display...
* Patch committed by Pavitra Subramaniam
Modified:
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/FastMessageFormat.java
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/util/FastMessageFormatTest.java
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/FastMessageFormat.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/FastMessageFormat.java?rev=1167242&r1=1167241&r2=1167242&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/FastMessageFormat.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/FastMessageFormat.java Fri Sep 9 15:15:20 2011
@@ -86,7 +86,27 @@ public class FastMessageFormat
for (int i = 0; i < formatLength; i++)
{
char ch = _formatText[i];
- if (ch == '{')
+
+ // Check for doubled-up quotes
+ if (ch == '\'' && (i+1 < formatLength) && (_formatText[i+1] == '\''))
+ {
+ /*
+ The tranlations tool uses special processing for single quotation marks that appear in
+ resource strings. In ResourceBundle files, if a message contains an argument placeholder,
+ e.g. {0} or {1}, it is assumed to be a format pattern for MessageFormat and the translation
+ tool automatically doubles all single quotes inside such a message. If the message contains
+ no arguments, it is expected to be used directly after loading from the bundle, without
+ processing with MessageFormat. Therefore, no quotes are doubled automatically in such a
+ message. This code change accounts for the presence of doubled quotes.
+ */
+
+ buffer.append(_formatText, lastStart, i - lastStart);
+
+ // skip one of the double quotes.
+ i++;
+ lastStart = i;
+ }
+ else if (ch == '{')
{
// Only check for single digit patterns that have an associated token.
if (i + 2 < formatLength && _formatText[i + 2] == '}')
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/util/FastMessageFormatTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/util/FastMessageFormatTest.java?rev=1167242&r1=1167241&r2=1167242&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/util/FastMessageFormatTest.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/test/java/org/apache/myfaces/trinidad/util/FastMessageFormatTest.java Fri Sep 9 15:15:20 2011
@@ -54,6 +54,16 @@ public class FastMessageFormatTest
String[] params = { "beef", "kosher", null };
String result = fmf.format(params);
assertEquals(result, "beef {{3} isn't {} {a} {12a}kosher {");
+
+ // tests doubled single quotes.
+ // Same as above, except doubled single quotes are replaced
+ // with a single single quote.
+ // Expected result: "beef {{3} isn't {} {a} {12a}kosher {"
+ FastMessageFormat fmf2 =
+ new FastMessageFormat("{0} {{3} isn''t {} {a} {12a}{2}{1} {");
+ String[] params2 = { "beef", "kosher", null };
+ result = fmf2.format(params2);
+ assertEquals(result, "beef {{3} isn't {} {a} {12a}kosher {");
}
}