diff --git a/CHANGELOG.md b/CHANGELOG.md index 3df47c3..3a98526 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changes * 2.6.next in progress + * Address [#537](https://github.com/seancorfield/honeysql/issues/537) by ignoring non-scalar values in metadata, and expanding support to numbers, and checking strings for suspicious characters. * Address [#536](https://github.com/seancorfield/honeysql/issues/536) by noting what will not work with PostgreSQL (but works with other databases). * Address [#533](https://github.com/seancorfield/honeysql/issues/533) by adding `honey.sql/*escape-?*` which can be bound to `false` to prevent `?` being escaped to `??` when used as an operator or function. * Address [#526](https://github.com/seancorfield/honeysql/issues/526) by using `format-var` in DDL, instead of `format-entity`. diff --git a/deps.edn b/deps.edn index fcc8311..84ed559 100644 --- a/deps.edn +++ b/deps.edn @@ -11,7 +11,7 @@ :1.9 {:override-deps {org.clojure/clojure {:mvn/version "1.9.0"}}} :1.10 {:override-deps {org.clojure/clojure {:mvn/version "1.10.3"}}} :1.11 {:override-deps {org.clojure/clojure {:mvn/version "1.11.4"}}} - :1.12 {:override-deps {org.clojure/clojure {:mvn/version "1.12.0-rc1"}}} + :1.12 {:override-deps {org.clojure/clojure {:mvn/version "1.12.0-rc2"}}} :elide ; to test #409 (assertion on helper docstrings) {:jvm-opts ["-Dclojure.compiler.elide-meta=[:doc]"]} diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 4069e83..e879371 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -159,6 +159,15 @@ ;; #533 mostly undocumented dynvar to prevent ? -> ?? escaping: (def ^:no-doc ^:dynamic *escape-?* true) +;; suspicious entity names: +(def ^:private suspicious #";") +(defn- suspicious? [s] (boolean (re-find suspicious s))) +(defn- suspicious-entity-check [entity] + (when-not *allow-suspicious-entities* + (when (suspicious? entity) + (throw (ex-info (str "suspicious character found in entity: " entity) + {:disallowed suspicious}))))) + ;; clause helpers (defn clause-body @@ -308,12 +317,8 @@ [%] (str/split % #"\.")))) parts (parts-fn col-e) - entity (str/join "." (map #(cond-> % (not= "*" %) (quote-fn)) parts)) - suspicious #";"] - (when-not *allow-suspicious-entities* - (when (re-find suspicious entity) - (throw (ex-info (str "suspicious character found in entity: " entity) - {:disallowed suspicious})))) + entity (str/join "." (map #(cond-> % (not= "*" %) (quote-fn)) parts))] + (suspicious-entity-check entity) entity)) (comment @@ -562,9 +567,18 @@ [x & [sep]] (when-let [data (meta x)] (let [items (reduce-kv (fn [acc k v] - (if (true? v) - (conj acc k) - (conj acc k v))) + (cond (number? v) + (conj acc (str v)) + (true? v) + (conj acc k) + (ident? v) + (conj acc k v) + (string? v) + (do + (suspicious-entity-check v) + (conj acc k v)) + :else ; quietly ignore other metadata + acc)) [] (reduce dissoc data @@ -576,7 +590,7 @@ (str/join (str sep " ") (mapv sql-kw items)))))) (comment - (format-meta ^{:foo true :bar :baz} []) + (format-meta ^{:foo true :bar :baz :original {:line 1} :top 10} []) (binding [*ignored-metadata* [:bar]] (format-meta ^{:foo true :bar :baz} []))