gnodet-bot commented on code in PR #30679:
URL: https://github.com/apache/camel/pull/30679#discussion_r4670363801


##########
components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileHelper.java:
##########
@@ -227,6 +233,82 @@ public static boolean isWithinDirectory(String 
compactTarget, String compactDir,
         return compactTarget.equals(dir) || compactTarget.startsWith(dir + 
separator);
     }
 
+    /**
+     * Determines whether a path on a remote server stays within a directory 
on that server, such as a path built from a
+     * name in the listing of the server. Both paths are compacted with
+     * {@link #compactPathForContainment(String, char)}, the way the server 
resolves them. A backslash separates
+     * segments, as / does: see {@link #isAmbiguousRemotePath(String)} for a 
path that is used without replacing its
+     * backslashes.
+     *
+     * @param  target    the path, not compacted
+     * @param  directory the directory the path must stay within, not 
compacted, or empty or {@code null} when no
+     *                   directory is configured
+     * @return           {@code true} if the path is the directory itself or a 
path inside it
+     */
+    public static boolean isWithinRemoteDirectory(String target, String 
directory) {
+        if (target == null) {
+            return false;
+        }
+        return isWithinDirectory(
+                compactPathForContainment(target, '/'), 
compactPathForContainment(directory != null ? directory : "", '/'),
+                '/');
+    }
+
+    /**
+     * Whether a remote path has both a backslash and a {@code ..} segment. A 
backslash is a path separator to some
+     * servers (such as a server on Windows) and part of a name to others, and 
the FTP client compacts the directory of
+     * a stepwise operation on the file separator of the platform Camel runs 
on only, so where such a path goes depends
+     * on the server and that platform, unless its backslashes are replaced by 
/ before it is used.
+     *
+     * @param  path the path
+     * @return      <tt>true</tt> if the path has both a backslash and a 
{@code ..} segment

Review Comment:
   💡 **Javadoc style (new):** `<tt>` is deprecated HTML. Use `{@code}` instead.
   
   ```suggestion
        * @return      {@code true} if the path has both a backslash and a 
{@code ..} segment
   ```



##########
components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java:
##########
@@ -217,6 +231,47 @@ private boolean handleDirectory(
         return false;
     }
 
+    /**
+     * Whether a directory entry, as listed by the server, is in the directory 
being listed. A server that lists the
+     * absolute path of each entry (handleDirectoryParserAbsoluteResult) lists 
the entries of the listed directory, so
+     * the absolute path ends with the path of the listed directory and the 
name of the entry. A relative name must be
+     * the name of the entry, followed by / at most, as a relative path of 
more than one name is not an entry of the
+     * listed directory. Both paths are compacted first.
+     *
+     * @param  listed        the name of the entry as listed
+     * @param  absolutePath  the path of the listed directory
+     * @param  directoryName the name of the entry
+     * @return               <tt>true</tt> if the entry is in the listed 
directory

Review Comment:
   💡 **Javadoc style (prior nit, still open):** `<tt>` is deprecated HTML. Use 
`{@code}` instead.
   
   ```suggestion
        * @return               {@code true} if the entry is in the listed 
directory
   ```



##########
components/camel-ftp-common/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java:
##########
@@ -142,6 +142,20 @@ public static void ensureRelativeFtpDirectory(Component 
ftpComponent, RemoteFile
         }
     }
 
+    /**
+     * Whether a directory name from a listing of the server is the name of 
one directory in the listed directory: not
+     * blank, not . or .., and without a / or a \. A stepwise recursive poll 
changes into such a directory one segment
+     * at a time, and back to its parent afterwards, so a name such as sub/.. 
or a\b would leave the poll in another
+     * directory than the listed one.
+     *
+     * @param  name the name of the directory, as listed
+     * @return      <tt>true</tt> if the poll can change into the directory

Review Comment:
   💡 **Javadoc style (prior nit, still open):** `<tt>` is deprecated HTML. Use 
`{@code}` instead.
   
   ```suggestion
        * @return      {@code true} if the poll can change into the directory
   ```



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