From 91bac5045c86676e1067b89b2614458061ea5dfd Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 6 May 2025 16:47:38 +0300 Subject: [PATCH 1/2] Fix multiline folding according to rfc2445 --- src/tick/alpha/ical.clj | 2 +- test/tick/alpha/ical_test.clj | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/tick/alpha/ical.clj b/src/tick/alpha/ical.clj index 4d1f82e..51e1541 100644 --- a/src/tick/alpha/ical.clj +++ b/src/tick/alpha/ical.clj @@ -263,7 +263,7 @@ [^java.io.BufferedReader rdr hold] (if-let [line (.readLine rdr)] (if (= (.charAt line 0) \space) - (recur rdr (conj hold line)) + (recur rdr (conj hold (.substring line 1))) (cons (str/join hold) (lazy-seq (unfolding-line-seq* rdr [line])))) [(str/join hold)])) diff --git a/test/tick/alpha/ical_test.clj b/test/tick/alpha/ical_test.clj index 6b4e10a..7a1cb7b 100644 --- a/test/tick/alpha/ical_test.clj +++ b/test/tick/alpha/ical_test.clj @@ -40,3 +40,23 @@ (is (= "DTSTART" name)) (is (= "US-EAST" (get params "TZID"))) (is (= "20180116T140000" value))))) + +(def multiline + "X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-SOME-HEADER-BREAKING-SOMEWHERE-AT- + 75=foobar;X-TITLE=Some Place:geo:44.815458,20.462758") + +(deftest parse-line-folding-test + (testing "Folded lines can be parsed" + (is (= {:name "X-APPLE-STRUCTURED-LOCATION", + :params + {"VALUE" "URI", + "X-SOME-HEADER-BREAKING-SOMEWHERE-AT-75" "foobar", + "X-TITLE" "Some Place"}, + :value "geo:44.815458,20.462758", + :string-value "geo:44.815458,20.462758"} + (-> multiline + char-array + io/reader + ical/unfolding-line-seq + first + ical/line->contentline))))) From af118476f213c65a18415e8865fbbacdefde74b6 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 6 May 2025 18:35:39 +0300 Subject: [PATCH 2/2] Ignore empty lines --- src/tick/alpha/ical.clj | 7 ++++--- test/tick/alpha/ical_test.clj | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/tick/alpha/ical.clj b/src/tick/alpha/ical.clj index 51e1541..09818b6 100644 --- a/src/tick/alpha/ical.clj +++ b/src/tick/alpha/ical.clj @@ -262,9 +262,10 @@ (defn unfolding-line-seq* [^java.io.BufferedReader rdr hold] (if-let [line (.readLine rdr)] - (if (= (.charAt line 0) \space) - (recur rdr (conj hold (.substring line 1))) - (cons (str/join hold) (lazy-seq (unfolding-line-seq* rdr [line])))) + (cond + (.isEmpty line) (recur rdr hold) + (= (.charAt line 0) \space) (recur rdr (conj hold (.substring line 1))) + :else (cons (str/join hold) (lazy-seq (unfolding-line-seq* rdr [line])))) [(str/join hold)])) (defn unfolding-line-seq [^java.io.BufferedReader rdr] diff --git a/test/tick/alpha/ical_test.clj b/test/tick/alpha/ical_test.clj index 7a1cb7b..8849411 100644 --- a/test/tick/alpha/ical_test.clj +++ b/test/tick/alpha/ical_test.clj @@ -60,3 +60,18 @@ ical/unfolding-line-seq first ical/line->contentline))))) + +(def multi-with-empty + "X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-SOME-HEADER-BREAKING-SOMEWHERE-AT- + 75=foobar;X-TITLE=Some Place:geo:44.815458,20.462758 + +FOO:bar") + +(deftest parse-line-ignore-empty-test + (testing "Empty lines are ignored" + (is (= ["X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-SOME-HEADER-BREAKING-SOMEWHERE-AT-75=foobar;X-TITLE=Some Place:geo:44.815458,20.462758" + "FOO:bar"] + (-> multi-with-empty + char-array + io/reader + ical/unfolding-line-seq)))))