boolean (@NotNull String pathBeforeSlash) { if (pathBeforeSlash.endsWith("/")) { return false; } int start = 0; while (true) { int i = pathBeforeSlash.indexOf("..", start); if (i == -1) break; if ((i == 0 || pathBeforeSlash.charAt(i-1) == '/') // /.. && (i == pathBeforeSlash.length() - 2 || pathBeforeSlash.charAt(i+2) == '/')) { // ../ return false; } start = i+1; } return true; }