apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.23k stars 2.08k forks source link

Removing '/./' in redirected URLs (Wicket-Feature) #4832

Open asfimport opened 6 years ago

asfimport commented 6 years ago

peter (Bug 62584): In addition to https://github.com/apache/jmeter/issues/2361 does Wicket not only produce collapsing URLs like

"app/path/../path2/"

but also relative paths like

"app/wicket/./login?0"

in redirected URLs.

Current Browsers fix URLs with "/./" by removing "/./" but not JMeter.

In this Bug the problem with relative paths shall be fixed by replacing "/./" by "/" in the URLs getting by redirection.

OS: All

asfimport commented 6 years ago

peter (migrated from Bugzilla): Patch for this Bug

Created attachment jmeter.patch_bug_62584: Patch

jmeter.patch_bug_62584 ````diff diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java index 032ba36..6b09814 100644 --- a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java +++ b/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java @@ -299,6 +299,11 @@ /** Whether to remove '/pathsegment/..' from redirects; default true */ private static final boolean REMOVESLASHDOTDOT = JMeterUtils.getPropDefault("httpsampler.redirect.removeslashdotdot", true); + + // Bug 62584 + /** Whether to remove '/./' from redirects; default false */ + private static final boolean REMOVESLASHDOTSLASH = + JMeterUtils.getPropDefault("httpsampler.redirect.removeslashdotslash", false); private static final String HTTP_PREFIX = HTTPConstants.PROTOCOL_HTTP+"://"; // $NON-NLS-1$ private static final String HTTPS_PREFIX = HTTPConstants.PROTOCOL_HTTPS+"://"; // $NON-NLS-1$ @@ -1564,6 +1569,9 @@ if (REMOVESLASHDOTDOT) { location = ConversionUtils.removeSlashDotDot(location); } + if (REMOVESLASHDOTSLASH) { + location = location.replaceAll("/./", "/"); + } // Browsers seem to tolerate Location headers with spaces, // replacing them automatically with %20. We want to emulate // this behaviour. ````
asfimport commented 6 years ago

@FSchumacher (migrated from Bugzilla): If you look at ConversionUtils#removeSlashDotDot, you will see, that it does a lot more than simply removing '/..' from the complete URL.

Maybe it would be a good idea to factor out the common logic of /.. and /. into a new method and delegate the old one and the new one (you would have to create, too) to it.

And by the way. String#replaceAll takes a regex as first command and '.' has a special meaning in regex, so it is probably a good idea to add test cases for the change :) It should be easier, if you take the route via ConversionUtils.