From c86fb15f4a5a78ac9f60df942aa4ff223a460e2a Mon Sep 17 00:00:00 2001 From: Walter Leibbrandt <23798+walterl@users.noreply.github.com> Date: Fri, 9 Aug 2019 03:19:39 +0200 Subject: [PATCH] Use locale agnostic `clojure.string/lower-case` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this change `clojure.string/lower-case` uses the default locale, turning (for example) "ID" into ":ıd" in the Turkish locale. --- src/toucan/db.clj | 8 ++++++-- src/toucan/util.clj | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/toucan/db.clj b/src/toucan/db.clj index ba79a82..8204550 100644 --- a/src/toucan/db.clj +++ b/src/toucan/db.clj @@ -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. @@ -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 diff --git a/src/toucan/util.clj b/src/toucan/util.clj index 633f2f1..9e9a855 100644 --- a/src/toucan/util.clj +++ b/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`). @@ -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))))