[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit FormControl.java,1.49,1.50 HttpUnitUtils.
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2004-12-26 20:33:45
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6551/src/com/meterware/httpunit Modified Files: FormControl.java HttpUnitUtils.java WebForm.java Log Message: bug #1087180 setting a numeric value into a form parameter was appending a trailing decimal zero Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- FormControl.java 2 Dec 2004 02:07:10 -0000 1.49 +++ FormControl.java 26 Dec 2004 20:33:34 -0000 1.50 @@ -789,10 +789,12 @@ public void set( String propertyName, Object value ) { - if (propertyName.equalsIgnoreCase( "value" )) { - _value[0] = (value == null) ? null : value.toString(); - } else { + if (!propertyName.equalsIgnoreCase( "value" )) { super.set( propertyName, value ); + } else if (value instanceof Number) { + _value[0] = HttpUnitUtils.trimmedValue( (Number) value ); + } else { + _value[0] = (value == null) ? null : value.toString(); } } } Index: HttpUnitUtils.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- HttpUnitUtils.java 29 Sep 2004 17:15:24 -0000 1.20 +++ HttpUnitUtils.java 26 Dec 2004 20:33:34 -0000 1.21 @@ -76,6 +76,20 @@ } + /** + * Returns a string representation of a number, trimming off any trailing decimal zeros. + */ + static String trimmedValue( Number number ) { + String rawNumber = number.toString(); + if (rawNumber.indexOf('.') == -1) return rawNumber; + + int index = rawNumber.length(); + while (rawNumber.charAt( index-1 ) == '0') index--; + if (rawNumber.charAt( index-1 ) == '.') index--; + return rawNumber.substring( 0, index ); + } + + /** * Decodes a URL safe string into its original form using the Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.101 retrieving revision 1.102 diff -u -r1.101 -r1.102 --- WebForm.java 29 Sep 2004 17:15:25 -0000 1.101 +++ WebForm.java 26 Dec 2004 20:33:34 -0000 1.102 @@ -737,27 +737,13 @@ } else if (value instanceof String) { setParameterValue( propertyName, (String) value ); } else if (value instanceof Number) { - setParameterValue( propertyName, roundedValue( (Number) value ) ); + setParameterValue( propertyName, HttpUnitUtils.trimmedValue( (Number) value ) ); } else { super.set( propertyName, value ); } } - /** - * Trim off any trailing zeros (and the decimal point if the result is an integer). - */ - private String roundedValue( Number number ) { - String rawNumber = number.toString(); - if (rawNumber.indexOf('.') == -1) return rawNumber; - - int index = rawNumber.length(); - while (rawNumber.charAt( index-1 ) == '0') index--; - if (rawNumber.charAt( index-1 ) == '.') index--; - return rawNumber.substring( 0, index ); - } - - public void setParameterValue( String name, String value ) { final Object scriptableObject = getParameter( name ).getScriptableObject(); if (scriptableObject instanceof ScriptableDelegate) { |