Author: markt Date: Mon Dec 10 09:28:46 2018 New Revision: 1848558 URL: http://svn.apache.org/viewvc?rev=1848558&view=rev Log: The single quote replacement code has never been quite right. Add some unit tests and use a regexp that better handles the various edge cases
Added: tomcat/trunk/test/org/apache/tomcat/buildutil/ tomcat/trunk/test/org/apache/tomcat/buildutil/translate/ tomcat/trunk/test/org/apache/tomcat/buildutil/translate/TestUtils.java (with props) Modified: tomcat/trunk/java/org/apache/tomcat/buildutil/translate/Utils.java Modified: tomcat/trunk/java/org/apache/tomcat/buildutil/translate/Utils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/buildutil/translate/Utils.java?rev=1848558&r1=1848557&r2=1848558&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/buildutil/translate/Utils.java (original) +++ tomcat/trunk/java/org/apache/tomcat/buildutil/translate/Utils.java Mon Dec 10 09:28:46 2018 @@ -29,7 +29,7 @@ public class Utils { private static final Pattern ADD_CONTINUATION = Pattern.compile("\\n", Pattern.MULTILINE); private static final Pattern ESCAPE_LEADING_SPACE = Pattern.compile("^(\\s)", Pattern.MULTILINE); - private static final Pattern FIX_SINGLE_QUOTE = Pattern.compile("([^'])'([^'])", Pattern.MULTILINE); + private static final Pattern FIX_SINGLE_QUOTE = Pattern.compile("(?<!')'(?!')", Pattern.MULTILINE); private Utils() { // Utility class. Hide default constructor. @@ -66,7 +66,7 @@ public class Utils { } if (result.contains("[{0}]")) { - result = FIX_SINGLE_QUOTE.matcher(result).replaceAll("$1''$2"); + result = FIX_SINGLE_QUOTE.matcher(result).replaceAll("''"); } return result; } Added: tomcat/trunk/test/org/apache/tomcat/buildutil/translate/TestUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/buildutil/translate/TestUtils.java?rev=1848558&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/buildutil/translate/TestUtils.java (added) +++ tomcat/trunk/test/org/apache/tomcat/buildutil/translate/TestUtils.java Mon Dec 10 09:28:46 2018 @@ -0,0 +1,50 @@ +/* +* 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.tomcat.buildutil.translate; + +import org.junit.Assert; +import org.junit.Test; + +public class TestUtils { + + @Test + public void testQuoteReplacement01() { + Assert.assertEquals("[{0}] a''a", Utils.formatValue("[{0}] a'a")); + } + + @Test + public void testQuoteReplacement02() { + Assert.assertEquals("[{0}] a''", Utils.formatValue("[{0}] a'")); + } + + + @Test + public void testQuoteReplacement03() { + Assert.assertEquals("''a [{0}]", Utils.formatValue("'a [{0}]")); + } + + @Test + public void testQuoteReplacement05() { + Assert.assertEquals("[{0}] ''a'' bbb", Utils.formatValue("[{0}] 'a' bbb")); + } + + @Test + public void testQuoteReplacement06() { + Assert.assertEquals("[{0}] ''aa'' bbb", Utils.formatValue("[{0}] 'aa' bbb")); + } + +} Propchange: tomcat/trunk/test/org/apache/tomcat/buildutil/translate/TestUtils.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org