From 01d4799fb2d5769e1c31144ef791cc26e4529b81 Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 6 Jul 2023 13:31:24 +0200 Subject: [PATCH] Implement and use `uri-string?` --- .../activity_pub_poc/activitystreams2.clj | 9 +++++---- .../domaindrivenarchitecture/activity_pub_poc/core.clj | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.clj b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.clj index e00e685..d74ac6d 100644 --- a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.clj +++ b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/activitystreams2.clj @@ -1,13 +1,14 @@ (ns org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 - (:require [clojure.spec.alpha :as s])) + (:require [clojure.spec.alpha :as s] + [org.domaindrivenarchitecture.activity-pub-poc.core :as core])) (s/def ::Object (s/or - :uri any? ; TODO: This should only check for uri + :uri core/uri-string? :map (s/keys :req-un [::id ::type] ;type darf nicht "Link" sein :opt-un [::attributedTo ::und-mehr]))) -(s/def ::id any?) ; TODO: This should only check for uri -(s/def ::type any?);(fn [s] (s/or (uri? s) (= s "Link")))) +(s/def ::id core/uri-string?) +(s/def ::type #(or (core/uri-string? %) (= % "Link"))) (s/def ::Link (s/keys :req-un [::type] ; type muss "Link" sein diff --git a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/core.clj b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/core.clj index 0aea4ac..2a4b39d 100644 --- a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/core.clj +++ b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/core.clj @@ -29,9 +29,12 @@ (defn type-string? [input] (re-matches #"[A-Z]" (str (first input)))) -(defn uri-string? [input] +(defn url-string? [input] (re-matches #"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)" input)) +(defn uri-string? [input] + (re-matches #"\w+:(\/?\/?)[^\s]+" input)) + (defn uri-vector? [input] (and (every? #(uri-string? %) input) (vector? input)))