@@ -237,20 +237,22 @@ public FQID(@NotNull String driveId, @NotNull String itemId) {
237237 }
238238
239239 /**
240- * removes "." and ".." segments from the path
240+ * removes "." and ".." segments from the path,
241+ * replaces all separators with '/',
242+ * discards the first leading and trailing separator
241243 * @param path to normalize
242- * @return the normalized path
244+ * @return the normalized relative path
243245 */
244246 @ NotNull
245- private String normalizePath (@ NotNull String path ) {
247+ private static String normalizePath (@ NotNull String path ) {
246248 StringBuilder normalized = new StringBuilder ();
247249 for (String part : path .split ("[/\\ \\ ]" )) {
248- if ("." .equals (part ) || ".." .equals (part )) {
250+ if (part . isEmpty () || "." .equals (part ) || ".." .equals (part )) {
249251 continue ;
250252 }
251253 normalized .append ('/' ).append (part );
252254 }
253- return normalized .substring (1 );
255+ return normalized .substring (Math . min ( normalized . length (), 1 ) );
254256 }
255257
256258 /**
@@ -260,13 +262,19 @@ private String normalizePath(@NotNull String path) {
260262 * @return joined path
261263 */
262264 @ NotNull
263- private String concatPath (@ NotNull String lhs , @ NotNull String rhs ) {
265+ private static String concatPath (@ NotNull String lhs , @ NotNull String rhs ) {
264266 if (rhs .isEmpty ()) {
265267 return lhs ;
266268 }
267269 if (lhs .isEmpty ()) {
268270 return rhs ;
269271 }
272+ if (lhs .endsWith ("/" )) {
273+ lhs = lhs .substring (0 , lhs .length () - 1 );
274+ }
275+ if (rhs .startsWith ("/" )) {
276+ rhs = rhs .substring (1 );
277+ }
270278 return lhs + '/' + rhs ;
271279 }
272280
0 commit comments