[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebRequest.java,1.55,1.56
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-05-04 15:09:08
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv23268/src/com/meterware/httpunit
Modified Files:
WebRequest.java
Log Message:
fixed bug #717280: Requests with '../' in them are not resolved properly
Index: WebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- WebRequest.java 27 Feb 2003 23:36:01 -0000 1.55
+++ WebRequest.java 4 May 2003 15:09:05 -0000 1.56
@@ -87,8 +87,49 @@
}
HttpsProtocolSupport.verifyProtocolSupport( getURLString().substring( 0, getURLString().indexOf( ':' ) ) );
}
- return spec.startsWith( "?" ) ? new URL( base + spec ) : new URL( base, spec );
+ return spec.startsWith( "?" ) ? new URL( base + spec ) : newCombinedURL( base, spec );
}
+ }
+
+
+ private URL newCombinedURL( final URL base, final String spec ) throws MalformedURLException {
+ if (base == null) return new URL( getNormalizedURL( spec ) );
+ else if (spec.startsWith( ".." )) return new URL( getNormalizedURL( getURLDirectory( base ) + spec ) );
+ else return new URL( base, getNormalizedURL( spec ) );
+ }
+
+
+ private String getURLDirectory( final URL base ) {
+ String url = base.toExternalForm();
+ int i = url.lastIndexOf( '/' );
+ return url.substring( 0, i+1 );
+ }
+
+
+ private String getNormalizedURL( String url ) {
+ if (url.lastIndexOf( "//" ) > url.indexOf( "://" ) + 1) return getNormalizedURL( stripDoubleSlashes( url ) );
+ if (url.indexOf( "/.." ) > 0) return getNormalizedURL( stripUpNavigation( url ) );
+ if (url.indexOf( "/." ) > 0) return getNormalizedURL( stripInPlaceNavigation( url ) );
+ return url;
+ }
+
+
+ private String stripInPlaceNavigation( String url ) {
+ int i = url.lastIndexOf( "/." );
+ return url.substring( 0, i+1 ) + url.substring( i+2 );
+ }
+
+
+ private String stripUpNavigation( String url ) {
+ int i = url.indexOf( "/.." );
+ int j = url.lastIndexOf( "/", i-1 );
+ return url.substring( 0, j+1 ) + url.substring( i+ 3 );
+ }
+
+
+ private String stripDoubleSlashes( String url ) {
+ int i = url.lastIndexOf( "//" );
+ return url.substring( 0, i ) + url.substring( i+1 );
}
|