Skip to content

Commit

Permalink
Improve performance of StringUtils#cleanPath
Browse files Browse the repository at this point in the history
  • Loading branch information
dreis2211 authored and jhoeller committed Mar 23, 2020
1 parent ac0363c commit 1c6dda3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -701,6 +701,10 @@ else if (TOP_PATH.equals(element)) {
}
}

// All path elements stayed the same - shortcut
if (pathArray.length == pathElements.size()) {
return prefix + pathToUse;
}
// Remaining top paths need to be retained.
for (int i = 0; i < tops; i++) {
pathElements.add(0, TOP_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ void cleanPath() {
assertThat(StringUtils.cleanPath("file:../")).isEqualTo("file:../");
assertThat(StringUtils.cleanPath("file:./../")).isEqualTo("file:../");
assertThat(StringUtils.cleanPath("file:.././")).isEqualTo("file:../");
assertThat(StringUtils.cleanPath("file:/mypath/spring.factories")).isEqualTo("file:/mypath/spring.factories");
assertThat(StringUtils.cleanPath("file:///c:/some/../path/the%20file.txt")).isEqualTo("file:///c:/path/the%20file.txt");
}

Expand Down

0 comments on commit 1c6dda3

Please sign in to comment.