Clojure

clojure.string/replace-first treats \ and $ specially when match is a string, unlike clojure.string/replace

Details

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

Description

clojure.string/replace only gives special treatment to replacement string when match is a regex pattern. clojure.string/replace-first does so in those cases, but also when match is a string to be matched literally. For example, these cases are not consistent with each other:

user=> (require '[clojure.string :as str])
nil
user=> (str/replace "food" "o" "$")
"f$$d"
user=> (str/replace-first "food" "o" "$")
java.lang.StringIndexOutOfBoundsException: String index out of range: 1 (NO_SOURCE_FILE:0)

Activity

Hide
Andy Fingerhut added a comment -

Suggested fix for CLJ-905, plus addition of function clojure.string/re-qr for quoting replacement strings that caller wishes to be treated literally when match is a pattern.

Show
Andy Fingerhut added a comment - Suggested fix for CLJ-905, plus addition of function clojure.string/re-qr for quoting replacement strings that caller wishes to be treated literally when match is a pattern.
Hide
Andy Fingerhut added a comment -

CLJ-870 has a proposed combined patch for this issue and that one.

Show
Andy Fingerhut added a comment - CLJ-870 has a proposed combined patch for this issue and that one.
Hide
Andy Fingerhut added a comment -

This issue should now be corrected with the patch, attached to CLJ-870, that was applied on Aug 18, 2012.

Show
Andy Fingerhut added a comment - This issue should now be corrected with the patch, attached to CLJ-870, that was applied on Aug 18, 2012.
Hide
Stuart Sierra added a comment -

CLJ-905 same status as CLJ-753: patch applied for CLJ-870 addresses this one, too, applied Aug 18, 2012

Show
Stuart Sierra added a comment - CLJ-905 same status as CLJ-753: patch applied for CLJ-870 addresses this one, too, applied Aug 18, 2012

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: