Skip to content

Commit

Permalink
Use locale agnostic clojure.string/lower-case
Browse files Browse the repository at this point in the history
Without this change `clojure.string/lower-case` uses the default locale,
turning (for example) "ID" into ":ıd" in the Turkish locale.
  • Loading branch information
walterl committed Aug 9, 2019
1 parent d5c48dc commit c86fb15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/toucan/db.clj
Expand Up @@ -153,7 +153,7 @@
(model-symb->ns 'CardFavorite) -> 'my-project.models.card-favorite"
[symb]
{:pre [(symbol? symb)]}
(symbol (str (models/root-namespace) \. (s/lower-case (s/replace (name symb) #"([a-z])([A-Z])" "$1-$2")))))
(symbol (str (models/root-namespace) \. (u/lower-case (s/replace (name symb) #"([a-z])([A-Z])" "$1-$2")))))

(defn- resolve-model-from-symbol
"Resolve the model associated with SYMB, calling `require` on its namespace if needed.
Expand Down Expand Up @@ -271,7 +271,11 @@
"Compile `honeysql-from` and call `jdbc/query` against the application database. Options are passed along to
`jdbc/query`."
[honeysql-form & {:as options}]
(jdbc/query (connection) (honeysql->sql honeysql-form) options))
(jdbc/query (connection)
(honeysql->sql honeysql-form)
; FIXME: This has already been fixed in `clojure.java.jdbc`, so
; this option can be removed when using >= 0.7.10.
(into options {:identifiers u/lower-case})))

(defn reducible-query
"Compile `honeysql-from` and call `jdbc/reducible-query` against the application database. Options are passed along
Expand Down
11 changes: 10 additions & 1 deletion src/toucan/util.clj
@@ -1,6 +1,7 @@
(ns toucan.util
"Utility functions used by other Toucan modules."
(:require [clojure.string :as s]))
(:require [clojure.string :as s])
(:import java.util.Locale))

(defn keyword->qualified-name
"Return keyword K as a string, including its namespace, if any (unlike `name`).
Expand All @@ -9,3 +10,11 @@
[k]
(when k
(s/replace (str k) #"^:" "")))

(defn lower-case
"Locale-agnostic version of `clojure.string/lower-case`.
`clojure.string/lower-case` uses the default locale in conversions, turning
`ID` into `ıd`, in the Turkish locale. This function always uses the
`Locale/US` locale."
[s]
(.. s toString (toLowerCase (Locale/US))))

0 comments on commit c86fb15

Please sign in to comment.