MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / removeDots

Method removeDots

src/main/java/org/htmlunit/WebRequest.java:220–241  ·  view source on GitHub ↗
(final String path)

Source from the content-addressed store, hash-verified

218 * so if we create a new match with a replacement, it is missed.
219 */
220 private static String removeDots(final String path) {
221 String newPath = path;
222
223 // remove occurrences at the beginning
224 newPath = REMOVE_DOTS_PATTERN.matcher(newPath).replaceAll("/");
225 if ("/..".equals(newPath)) {
226 newPath = "/";
227 }
228
229 // single dots have no effect, so just remove them
230 while (DOT_PATTERN.matcher(newPath).find()) {
231 newPath = DOT_PATTERN.matcher(newPath).replaceAll("/");
232 }
233
234 // mid-path double dots should be removed WITH the previous subdirectory and replaced
235 // with "/" BUT ONLY IF that subdirectory's not also ".." (a regex lookahead helps with this)
236 while (DOT_DOT_PATTERN.matcher(newPath).find()) {
237 newPath = DOT_DOT_PATTERN.matcher(newPath).replaceAll("/");
238 }
239
240 return newPath;
241 }
242
243 private static URL buildUrlWithNewPath(URL url, final String newPath) {
244 try {

Callers 1

setUrlMethod · 0.95

Calls 3

replaceAllMethod · 0.80
equalsMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected