(final String path)
| 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 { |
no test coverage detected