raboof commented on code in PR #396:
URL: https://github.com/apache/commons-vfs/pull/396#discussion_r1445437788


##########
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java:
##########
@@ -455,6 +455,156 @@ public static boolean fixSeparators(final StringBuilder 
name) {
         return changed;
     }
 
+    private static class PathNormalizer {
+        private final StringBuilder path;
+        private int cursor = 0;
+        private int lastSeparator;
+        private int end;
+        PathNormalizer(StringBuilder path) {
+            this.path = path;
+            this.end = path.length();
+        }
+        void run() throws FileSystemException {
+            lastSeparator = cursor;
+            readSeparator();
+            while (cursor < end) {
+                consumeSeparators();
+                if (readDot()) {
+                    if (readDot()) {
+                        int beforeNextSeparator = cursor;
+                        if (readSeparator() || cursor == end) {
+                            // '/../'
+                            removePreviousElement(beforeNextSeparator);
+                        } else {
+                            // '/..other'
+                            readNonSeparators();
+                            lastSeparator = cursor;
+                            readSeparator();
+                        }
+                    } else {
+                        int beforeNextSeparator = cursor;
+                        if (readSeparator() || cursor == end) {
+                            // '/./'
+                            path.delete(lastSeparator, beforeNextSeparator);
+                            cursor = lastSeparator + (cursor - 
beforeNextSeparator);
+                            this.end = path.length();
+                        } else {
+                            // '/.other'
+                            readNonSeparators();
+                            lastSeparator = cursor;
+                            readSeparator();
+                        }
+                    }
+                } else {
+                    readToNextSeparator();
+                    lastSeparator = cursor;
+                    readSeparator();
+                }
+            }
+        }
+        private void consumeSeparators() {
+            boolean consuming = true;
+            while (consuming) {
+                consuming = consumeSeparator();
+            }
+        }
+        private void readNonSeparators() {
+            boolean reading = true;
+            while (reading) {
+                reading = readNonSeparator();
+            }

Review Comment:
   hmm, it seems PMD won't let me



-- 
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]

Reply via email to