mirror of
https://github.com/penpot/penpot.git
synced 2025-06-29 01:56:59 +02:00
🎉 Add preprocessing to svg parse method.
This commit is contained in:
parent
7cc4873dd4
commit
9f5c19244d
1 changed files with 13 additions and 3 deletions
|
@ -12,7 +12,7 @@
|
||||||
[app.util.services :as sv]
|
[app.util.services :as sv]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.xml :as xml]
|
[clojure.xml :as xml]
|
||||||
[integrant.core :as ig])
|
[cuerdas.core :as str])
|
||||||
(:import
|
(:import
|
||||||
javax.xml.XMLConstants
|
javax.xml.XMLConstants
|
||||||
javax.xml.parsers.SAXParserFactory
|
javax.xml.parsers.SAXParserFactory
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
(defn- secure-parser-factory
|
(defn- secure-parser-factory
|
||||||
[s ch]
|
[s ch]
|
||||||
(.. (doto (SAXParserFactory/newInstance)
|
(.. (doto (SAXParserFactory/newInstance)
|
||||||
(.setFeature javax.xml.XMLConstants/FEATURE_SECURE_PROCESSING true)
|
(.setFeature XMLConstants/FEATURE_SECURE_PROCESSING true)
|
||||||
(.setFeature "http://apache.org/xml/features/disallow-doctype-decl" true))
|
(.setFeature "http://apache.org/xml/features/disallow-doctype-decl" true))
|
||||||
(newSAXParser)
|
(newSAXParser)
|
||||||
(parse s ch)))
|
(parse s ch)))
|
||||||
|
@ -38,11 +38,21 @@
|
||||||
:code :invalid-svg-file
|
:code :invalid-svg-file
|
||||||
:cause e))))
|
:cause e))))
|
||||||
|
|
||||||
|
(declare pre-process)
|
||||||
|
|
||||||
(s/def ::data ::us/string)
|
(s/def ::data ::us/string)
|
||||||
(s/def ::parsed-svg (s/keys :req-un [::data]))
|
(s/def ::parsed-svg (s/keys :req-un [::data]))
|
||||||
|
|
||||||
(sv/defmethod ::parsed-svg
|
(sv/defmethod ::parsed-svg
|
||||||
[_ {:keys [data] :as params}]
|
[_ {:keys [data] :as params}]
|
||||||
(parse data))
|
(->> data pre-process parse))
|
||||||
|
|
||||||
|
;; --- PROCESSORS
|
||||||
|
|
||||||
|
(defn strip-doctype
|
||||||
|
[data]
|
||||||
|
(cond-> data
|
||||||
|
(str/includes? data "<!DOCTYPE")
|
||||||
|
(str/replace #"<\!DOCTYPE[^>]+>" "")))
|
||||||
|
|
||||||
|
(def pre-process strip-doctype)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue