cziegeler commented on code in PR #94:
URL:
https://github.com/apache/sling-org-apache-sling-api/pull/94#discussion_r4560771623
##########
src/main/java/org/apache/sling/api/resource/path/PathBuilder.java:
##########
@@ -68,12 +78,21 @@ public PathBuilder append(final String path) {
}
/**
- * Returns the path
+ * Returns the normalized path without changing the accumulated fragments.
+ * Dot segments are resolved, duplicate slashes are collapsed, and trailing
+ * slashes are removed except for the root path.
*
- * @return the path
+ * @return the normalized absolute path
+ * @throws IllegalArgumentException if the path cannot be normalized, for
example
+ * because it traverses above root
*/
@Override
public String toString() {
- return sb.toString();
+ final String path = sb.toString();
+ final String normalizedPath = ResourceUtil.normalize(path);
+ if (normalizedPath == null) {
+ throw new IllegalArgumentException("Path cannot be normalized");
Review Comment:
Re-using toString() to get the path was a mistake, as Konrad says, an
explicit getter method would be much better.
And potentially we will break code by changing this method now, obviously
introducing a new method means no one will switch to that new method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]