tools.namespace

Function ns-file-name makes incorrect call to clojure.string/replace when File/separator is "\\" (e.g. Windows)

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code

Description

On Windows, where File/separator is a string consisting of a single backslash character:

user=> (require '[clojure.string :as str])
nil

;; This works as expected, because str/replace with second arg being a string handles arbitrary strings as the third arg
user=> (str/replace "foo.bar" "." File/separator)
"foo\\bar"

;; This gives an exception, because str/replace with second arg being a regex treats backslash characters in third arg specially.
user=> (str/replace "foo.bar" #"\." File/separator)
StringIndexOutOfBoundsException String index out of range: 1  java.lang.String.charAt (String.java:658)

;; This works as expected, but is more complex than the first alternative above
user=> (str/replace "foo.bar" #"\." (str/re-quote-replacement File/separator))
"foo\\bar"

I'd recommend using str/replace calls like the first one above when the things you want to replace are constant strings.

Activity

Hide
Andy Fingerhut added a comment -

Patch tns-22-v1.patch changes the only 2 calls to clojure.string/replace I found in tools.namespace that could have their second arg be a constant string rather than a regex.

Show
Andy Fingerhut added a comment - Patch tns-22-v1.patch changes the only 2 calls to clojure.string/replace I found in tools.namespace that could have their second arg be a constant string rather than a regex.
Hide
Stuart Sierra added a comment -

In release 0.2.6

Show
Stuart Sierra added a comment - In release 0.2.6

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: