Skip to content

Commit 5658fc2

Browse files
committed
FIX cgrand#90
- upgrade jsoup to 1.8.3 - test html-resource with jsoup (jsoup always adds a <head>, not tagsoup) - add jsoup/tagsoup fixtures to existing tests - pass tests
1 parent 00aa3ee commit 5658fc2

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/net/cgrand/enlive_html.clj

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
(ns net.cgrand.enlive-html
1212
"enlive-html is a selector-based transformation and extraction engine."
1313
(:refer-clojure :exclude [flatmap])
14-
(:require [net.cgrand.tagsoup :as tagsoup])
14+
(:require [net.cgrand.tagsoup :as tagsoup]
15+
[net.cgrand.jsoup :as jsoup])
1516
(:require [net.cgrand.xml :as xml])
1617
(:require [clojure.string :as str])
1718
(:require [clojure.zip :as z]))
@@ -106,7 +107,7 @@
106107
[stream loader]
107108
(loader stream))
108109

109-
(defmethod register-resource! java.net.URL
110+
(defmethod register-resource! java.net.URL
110111
[^java.net.URL url]
111112
(alter-meta! *ns* update-in [:net.cgrand.reload/deps] (fnil conj #{}) url))
112113

@@ -142,7 +143,7 @@
142143
([t a b c d e] (-> t (conj! a) (conj! b) (conj! c) (conj! d) (conj! e)))
143144
([t a b c d e f] (-> t (conj! a) (conj! b) (conj! c) (conj! d) (conj! e) (conj! f)))
144145
([t a b c d e f g] (-> t (conj! a) (conj! b) (conj! c) (conj! d) (conj! e) (conj! f) (conj! g)))
145-
([t a b c d e f g & more]
146+
([t a b c d e f g & more]
146147
(reduce conj! (-> t (conj! a) (conj! b) (conj! c) (conj! d) (conj! e) (conj! f) (conj! g))
147148
more)))
148149

@@ -684,12 +685,12 @@
684685
:else node)))))
685686

686687
(defn replace-words
687-
"Takes a map of words to replacement strings and replaces
688+
"Takes a map of words to replacement strings and replaces
688689
all occurences. Does not recurse, you have to pair it with an appropriate
689690
selector."
690-
[words-to-replacements]
691+
[words-to-replacements]
691692
(replace-vars
692-
(java.util.regex.Pattern/compile (str "\\b(" (str/join "|" (map #(java.util.regex.Pattern/quote %) (keys words-to-replacements))) ")\\b"))
693+
(java.util.regex.Pattern/compile (str "\\b(" (str/join "|" (map #(java.util.regex.Pattern/quote %) (keys words-to-replacements))) ")\\b"))
693694
words-to-replacements
694695
identity))
695696

test/net/cgrand/enlive_html/test.clj

+24-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
(:use net.cgrand.enlive-html)
1313
(:require [net.cgrand.xml :as xml])
1414
(:require [clojure.zip :as z])
15-
(:use [clojure.test :only [deftest is are run-all-tests]]))
15+
(:use [clojure.test :only [deftest is are run-all-tests use-fixtures]])
16+
(:require [net.cgrand.tagsoup :as tagsoup]
17+
[net.cgrand.jsoup :as jsoup]))
1618

1719
;; test utilities
1820
(defn- normalize [x]
@@ -314,3 +316,24 @@
314316
"A B"))
315317
(is (= ((replace-words {"Donald" "Mickey" "Duck" "Mouse"}) "Donald Duckling Duck")
316318
"Mickey Duckling Mouse")))
319+
320+
(deftest jsoup-snippet
321+
;; Jsoup always generates a head
322+
(is (= (html-resource (-> "<html><head></head><body><h1>Hi, cgrand!</h1></body></html>"
323+
(.getBytes "UTF-8")
324+
java.io.ByteArrayInputStream.)
325+
{:parser tagsoup/parser})
326+
(html-resource (-> "<html><head></head><body><h1>Hi, cgrand!</h1></body></html>"
327+
(.getBytes "UTF-8")
328+
java.io.ByteArrayInputStream.)
329+
{:parser jsoup/parser}))))
330+
331+
(defn fixture-jsoup-parser [f]
332+
(set-ns-parser! jsoup/parser)
333+
(f))
334+
335+
(defn fixture-tsoup-parser [f]
336+
(set-ns-parser! tagsoup/parser)
337+
(f))
338+
339+
(use-fixtures :each fixture-tsoup-parser fixture-jsoup-parser)

0 commit comments

Comments
 (0)