summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2025-10-19 18:12:40 +0300
committerAsko Nõmm <asko@nmm.ee>2025-10-19 18:12:40 +0300
commitad98bfddb09c6be641ff6755bb8caefc50f1636d (patch)
tree205661db6741879a8b04c8023350fcb0a07cf0e6 /src
parent9276f08031242c13ee25c8f89c22e4f65cff004b (diff)
#3: Fixes an issue where if the attribute value contained forward slashes, it would break the attribute parsing.
Diffstat (limited to 'src')
-rw-r--r--src/dompa/coordinates.cljc31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/dompa/coordinates.cljc b/src/dompa/coordinates.cljc
index ebe9b65..e5ca5e8 100644
--- a/src/dompa/coordinates.cljc
+++ b/src/dompa/coordinates.cljc
@@ -265,13 +265,16 @@
class=\"test\"
```"
[html]
- (->> (subs html 1)
- (take-while #(not (contains? #{\> \/} %)))
- (partition-by #(= % \space))
- (drop 1)
- flatten
- (apply str)
- str/trim))
+ (let [attrs-html (->> (subs html 1)
+ (take-while #(not (contains? #{\>} %)))
+ (partition-by #(= % \space))
+ (drop 1)
+ flatten
+ (apply str)
+ str/trim)]
+ (if (= \/ (last attrs-html))
+ (subs attrs-html 0 (dec (count attrs-html)))
+ attrs-html)))
(defn- html-str->node-attrs
"Turns a given `html` string into an attribute map, e.g:
@@ -294,10 +297,10 @@
:has-attrs? false
:attrs []}]
(as-> (html->str->node-attrs-reducer-fn attrs-html) $
- (reduce $ default-reducer-state indexed-attrs-html)
- (remove str/blank? (:attrs $))
- (map parse-html-attr-str $)
- (into {} $)))))
+ (reduce $ default-reducer-state indexed-attrs-html)
+ (remove str/blank? (:attrs $))
+ (map parse-html-attr-str $)
+ (into {} $)))))
(defn- construct-node
"Constructs a node map from `node-html` string and
@@ -306,9 +309,9 @@
(let [node-name (html-str->node-name node-html)
node-attrs (html-str->node-attrs node-html)]
(cond-> {:node/name node-name}
- (= node-name :dompa/text) (assoc :node/value node-html)
- (not (nil? node-attrs)) (assoc :node/attrs node-attrs)
- (not (nil? node-children)) (assoc :node/children node-children))))
+ (= node-name :dompa/text) (assoc :node/value node-html)
+ (not (nil? node-attrs)) (assoc :node/attrs node-attrs)
+ (not (nil? node-children)) (assoc :node/children node-children))))
(defn ->nodes
"Transform given `html` according to given `coordinates` into