Return-Path: Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: (qmail 70446 invoked from network); 3 Jan 2011 18:57:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Jan 2011 18:57:15 -0000 Received: (qmail 900 invoked by uid 500); 3 Jan 2011 18:57:15 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 849 invoked by uid 500); 3 Jan 2011 18:57:14 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 841 invoked by uid 99); 3 Jan 2011 18:57:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jan 2011 18:57:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jan 2011 18:57:13 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4669723889B2; Mon, 3 Jan 2011 18:56:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1054711 - in /ant/core/trunk/src: main/org/apache/tools/ant/filters/ main/org/apache/tools/ant/util/ tests/junit/org/apache/tools/ant/util/ Date: Mon, 03 Jan 2011 18:56:53 -0000 To: notifications@ant.apache.org From: antoine@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110103185653.4669723889B2@eris.apache.org> Author: antoine Date: Mon Jan 3 18:56:52 2011 New Revision: 1054711 URL: http://svn.apache.org/viewvc?rev=1054711&view=rev Log: fix for bug 50515, incorrect unicode escapes in propertyfile task Added: ant/core/trunk/src/main/org/apache/tools/ant/util/UnicodeUtil.java ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/UnicodeUtilTest.java Modified: ant/core/trunk/src/main/org/apache/tools/ant/filters/EscapeUnicode.java ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java Modified: ant/core/trunk/src/main/org/apache/tools/ant/filters/EscapeUnicode.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/filters/EscapeUnicode.java?rev=1054711&r1=1054710&r2=1054711&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/filters/EscapeUnicode.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/filters/EscapeUnicode.java Mon Jan 3 18:56:52 2011 @@ -20,6 +20,8 @@ package org.apache.tools.ant.filters; import java.io.IOException; import java.io.Reader; +import org.apache.tools.ant.util.UnicodeUtil; + /** * This method converts non-latin characters to unicode escapes. * Useful to load properties containing non latin @@ -85,14 +87,7 @@ public class EscapeUnicode if (ch != -1) { char achar = (char) ch; if (achar >= '\u0080') { - unicodeBuf = new StringBuffer("u0000"); - String s = Integer.toHexString(ch); - //replace the last 0s by the chars contained in s - for (int i = 0; i < s.length(); i++) { - unicodeBuf.setCharAt(unicodeBuf.length() - - s.length() + i, - s.charAt(i)); - } + unicodeBuf = UnicodeUtil.EscapeUnicode(achar); ch = '\\'; } } Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java?rev=1054711&r1=1054710&r2=1054711&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java Mon Jan 3 18:56:52 2011 @@ -567,12 +567,8 @@ public class LayoutPreservingProperties * @return the unicode escape sequence */ private String escapeUnicode(char ch) { - StringBuffer buffy = new StringBuffer("\\u"); - String hex = Integer.toHexString((int)ch); - buffy.append("0000".substring(4-hex.length())); - buffy.append(hex); - return buffy.toString(); - } + return "\\" + UnicodeUtil.EscapeUnicode(ch); + } /** * Remove the comments in the leading up the {@link logicalLines} Added: ant/core/trunk/src/main/org/apache/tools/ant/util/UnicodeUtil.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/UnicodeUtil.java?rev=1054711&view=auto ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/util/UnicodeUtil.java (added) +++ ant/core/trunk/src/main/org/apache/tools/ant/util/UnicodeUtil.java Mon Jan 3 18:56:52 2011 @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.util; + +/** + * Contains one helper method to create a backslash u escape + * + * @since Ant 1.8.3 + */ +public class UnicodeUtil { + /** + * returns the unicode representation of a char without the leading backslash + * @param ch + * @return unicode representation of a char for property files + */ + public static StringBuffer EscapeUnicode(char ch) { + StringBuffer unicodeBuf = new StringBuffer("u0000"); + String s = Integer.toHexString(ch); + //replace the last 0s by the chars contained in s + for (int i = 0; i < s.length(); i++) { + unicodeBuf.setCharAt(unicodeBuf.length() + - s.length() + i, + s.charAt(i)); + } + return unicodeBuf; + } +} Added: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/UnicodeUtilTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/UnicodeUtilTest.java?rev=1054711&view=auto ============================================================================== --- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/UnicodeUtilTest.java (added) +++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/UnicodeUtilTest.java Mon Jan 3 18:56:52 2011 @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.util; + +import junit.framework.TestCase; + +public class UnicodeUtilTest extends TestCase { + + public void testChineseWord() { + String word = "\u81ea\u7531"; + assertEquals("u81ea", UnicodeUtil.EscapeUnicode(word.charAt(0)).toString()); + assertEquals("u7531", UnicodeUtil.EscapeUnicode(word.charAt(1)).toString()); + } + +}