He-Pin commented on code in PR #1191:
URL: https://github.com/apache/pekko-http/pull/1191#discussion_r3679536843


##########
http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/FileAndResourceDirectives.scala:
##########
@@ -412,15 +429,24 @@ object DirectoryListing {
       def maxNameLength(seq: Seq[(File, String)]) = if (seq.isEmpty) 0 else 
seq.map(_._2.length).max
       val maxNameLen = math.max(maxNameLength(directoryFilesAndNames) + 1, 
maxNameLength(fileFilesAndNames))
       val sb = new java.lang.StringBuilder
-      
sb.append(html(0)).append(path).append(html(1)).append(path).append(html(2))
+      val escapedPath = escapeHtml(path)
+      
sb.append(html(0)).append(escapedPath).append(html(1)).append(escapedPath).append(html(2))
       if (!isRoot) {
         val secondToLastSlash = path.lastIndexOf('/', path.lastIndexOf('/', 
path.length - 1) - 1)

Review Comment:
   Nit: `escapeHtml(path)` here is called once per file/directory entry, but 
you already computed `escapedPath` a few lines above. Could just reuse it:
   
   ```scala
   sb.append("<a 
href=\"").append(escapedPath).append(escapedName).append("\">").append(escapedName).append("</a>")
   ```
   
   Avoids redundant escaping in directories with many entries.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to