fixes #537 by sanitizing metadata while expanding support to numbers
Signed-off-by: Sean Corfield <sean@corfield.org>
This commit is contained in:
parent
ae62d2b474
commit
bf34a23e68
3 changed files with 26 additions and 11 deletions
|
|
@ -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`.
|
||||
|
|
|
|||
2
deps.edn
2
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]"]}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
(cond (number? v)
|
||||
(conj acc (str v))
|
||||
(true? v)
|
||||
(conj acc k)
|
||||
(conj acc k v)))
|
||||
(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} []))
|
||||
|
|
|
|||
Loading…
Reference in a new issue