diff options
| author | eltrac <hi@eltr.ac> | 2026-09-16 20:41:56 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-09-16 21:16:47 +0800 |
| commit | deece0afb0b446f14f8fa70b730ef2e6bcf0b716 (patch) | |
| tree | 2885033f750c06d8dda5824ef325100741b0ec0a /src | |
| parent | af8ac86e5bae4569c25f3b52c7c051a60bb425c9 (diff) | |
receiver, mf, utils: bug fixes
microformats: fix assertion error
:post and :pre hooks enforce spec but for now we just need to log these
issues and analyze them. no need to throw exception for that.
---
receiver: fix NullPointerException when source/target is nil
when an incomplete webmention request (e.g. only source is included in
POST parameters), it throws Exception:
java.lang.NullPointerException: Cannot invoke "Object.toString()"
because "s" is null
this is because `remove-anchor` (which will soon be replaced with
weepinbell.utils.url/normalize) did not check if `url` is string or nil.
---
utils: fix incorrectly derefing a map
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/microformats/wrapper.clj | 6 | ||||
| -rw-r--r-- | src/weepinbell/receiver.clj | 3 | ||||
| -rw-r--r-- | src/weepinbell/utils.clj | 2 |
3 files changed, 5 insertions, 6 deletions
diff --git a/src/weepinbell/microformats/wrapper.clj b/src/weepinbell/microformats/wrapper.clj index 42975e0..fdf8bbd 100644 --- a/src/weepinbell/microformats/wrapper.clj +++ b/src/weepinbell/microformats/wrapper.clj @@ -53,7 +53,6 @@ (defn- get-card-info "Get essential information of an h-card item and flatten it into a map." [card] - {:post [(s/valid? ::mf-h-card %)]} (when (and card (= (get-mf-type card) "h-card")) (let [data {:name (get-prop-first card :name) @@ -61,13 +60,12 @@ :photo (get-prop-first card :photo) :url (get-prop-first card :url)}] (when-not (s/valid? ::mf-h-card data) - (timbre/warn "microformats h-card in bad form")) + (timbre/warn "microformats h-card in bad form:" data)) data))) (defn wrap-entry "Wrap parsed raw microformats (h-entry) data. If no h-entry found, return nil." [entry] - {:post [(s/valid? ::mf-h-entry %)]} ;; make sure it's h-entry (when (and entry (= (get-mf-type entry) "h-entry")) @@ -76,6 +74,6 @@ :published (get-prop-first entry :published) :content (javamap->map (get-prop-first entry :content))}] (when-not (s/valid? ::mf-h-entry data) - (timbre/warn "microformats h-entry in bad form")) + (timbre/warn "microformats h-entry in bad form:" data)) data))) diff --git a/src/weepinbell/receiver.clj b/src/weepinbell/receiver.clj index a0779dd..8a77aad 100644 --- a/src/weepinbell/receiver.clj +++ b/src/weepinbell/receiver.clj @@ -9,7 +9,8 @@ (defn- remove-anchor "Takes a URL string. Removes anchor (#...)" [url] - (string/replace url #"#.*" "")) + (when (string? url) + (string/replace url #"#.*" ""))) ;; end utilities ;; validation and verification diff --git a/src/weepinbell/utils.clj b/src/weepinbell/utils.clj index a2e0cd9..6b862ab 100644 --- a/src/weepinbell/utils.clj +++ b/src/weepinbell/utils.clj @@ -22,7 +22,7 @@ (when content-length (timbre/info "File size:" content-length "bytes")) ;; write to output stream - (with-open [in (:body @response) + (with-open [in (:body response) out (io/output-stream file)] (io/copy in out)) (timbre/info "Download success.") |
