Author: gseitz Date: Sat Nov 3 18:43:39 2007 New Revision: 591721 URL: http://svn.apache.org/viewvc?rev=591721&view=rev Log: WICKET-1015: PropertyVariableInterpolator#getString returns a string with escaped single quotes added tests for PropertyVariableInterpolator enhanced test for StringResourceModel
Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java (with props) Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.java wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.java URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.java?rev=591721&r1=591720&r2=591721&view=diff ============================================================================== --- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.java (original) +++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolator.java Sat Nov 3 18:43:39 2007 @@ -17,6 +17,7 @@ package org.apache.wicket.util.string.interpolator; import org.apache.wicket.util.lang.PropertyResolver; +import org.apache.wicket.util.string.Strings; /** * Interpolates values into <code>String</code>s that are produced by interpreting property @@ -84,6 +85,6 @@ protected String getValue(final String variableName) { Object value = PropertyResolver.getValue(variableName, model); - return (value != null) ? value.toString() : null; + return value != null ? Strings.replaceAll(value.toString(), "'", "''").toString() : null; } } Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java?rev=591721&r1=591720&r2=591721&view=diff ============================================================================== --- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java (original) +++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.java Sat Nov 3 18:43:39 2007 @@ -111,7 +111,7 @@ Assert.assertEquals("Text should be as expected", "It's sunny, wear sunscreen", model .getString()); ws.setCurrentStatus("raining"); - Assert.assertEquals("Text should be as expected", "It's raining, take an umberella", model + Assert.assertEquals("Text should be as expected", "It's raining, take an umbrella", model .getString()); } @@ -122,11 +122,17 @@ public void testGetPropertySubstitutedResource() { StringResourceModel model = new StringResourceModel("weather.message", page, wsModel); - Assert.assertEquals("Text should be as expected", - "Weather station reports that the temperature is 25.7 \u00B0C", model.getString()); + Assert + .assertEquals( + "Text should be as expected", + "Weather station \"Europe''s main weather station\" reports that the temperature is 25.7 \u00B0C", + model.getString()); ws.setCurrentTemperature(11.5); - Assert.assertEquals("Text should be as expected", - "Weather station reports that the temperature is 11.5 \u00B0C", model.getString()); + Assert + .assertEquals( + "Text should be as expected", + "Weather station \"Europe''s main weather station\" reports that the temperature is 11.5 \u00B0C", + model.getString()); } /** @@ -138,7 +144,7 @@ Calendar cal = Calendar.getInstance(); cal.set(2004, Calendar.OCTOBER, 15, 13, 21); MessageFormat format = new MessageFormat( - "The report for {0,date,medium}, shows the temparature as {2,number,###.##} {3} and the weather to be {1}", + "The report for {0,date,medium}, shows the temperature as {2,number,###.##} {3} and the weather to be {1}", page.getLocale()); StringResourceModel model = new StringResourceModel("weather.detail", page, wsModel, new Object[] { cal.getTime(), "${currentStatus}", @@ -242,6 +248,7 @@ { private static final long serialVersionUID = 1L; + private final String name = "Europe's main weather station"; private String currentStatus = "sunny"; @@ -285,6 +292,14 @@ public String getUnits() { return "\u00B0C"; + } + + /** + * @return name + */ + public String getName() + { + return name; } } Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties?rev=591721&r1=591720&r2=591721&view=diff ============================================================================== --- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties (original) +++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/model/StringResourceModelTest.properties Sat Nov 3 18:43:39 2007 @@ -18,6 +18,6 @@ # simple.text=Simple text weather.sunny=It's sunny, wear sunscreen -weather.raining=It's raining, take an umberella -weather.message=Weather station reports that the temperature is ${currentTemperature} ${units} -weather.detail=The report for {0,date,medium}, shows the temparature as {2,number,###.##} {3} and the weather to be {1} +weather.raining=It's raining, take an umbrella +weather.message=Weather station "${name}" reports that the temperature is ${currentTemperature} ${units} +weather.detail=The report for {0,date,medium}, shows the temperature as {2,number,###.##} {3} and the weather to be {1} \ No newline at end of file Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java?rev=591721&view=auto ============================================================================== --- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java (added) +++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java Sat Nov 3 18:43:39 2007 @@ -0,0 +1,66 @@ +/* + * 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.wicket.util.string.interpolator; + +import junit.framework.TestCase; + +/** + * Tests [EMAIL PROTECTED] PropertyVariableInterpolator} + * + * @author Gerolf Seitz + */ +public class PropertyVariableInterpolatorTest extends TestCase +{ + /** + * + */ + public void testWithValue() + { + TestClass object = new TestClass("value"); + String result = PropertyVariableInterpolator.interpolate("${key}", object); + assertEquals("value", result.toString()); + } + + /** + * + */ + public void testWithoutValue() + { + String result = PropertyVariableInterpolator.interpolate("${key}", null); + assertEquals("${key}", result.toString()); + } + + /** + * + */ + public void testWithValueWithSingleQuotes() + { + TestClass object = new TestClass("'value '' with multiple' quotes'"); + String result = PropertyVariableInterpolator.interpolate("${key}", object); + assertEquals("''value '''' with multiple'' quotes''", result); + } + + private static class TestClass + { + private final String key; + + public TestClass(String key) + { + this.key = key; + } + } +} Propchange: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/string/interpolator/PropertyVariableInterpolatorTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain