File: encode.clj

package info (click to toggle)
lambdaisland-uri-clojure 1.13.95-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 240 kB
  • sloc: xml: 88; sh: 28; makefile: 12
file content (89 lines) | stat: -rw-r--r-- 3,860 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(ns encode
  (:require [lambdaisland.uri :as uri]
            [lambdaisland.uri.normalize :as normalize]))

(-> (uri/uri "https://example.com/")
    (assoc :query (str "src=" (normalize/percent-encode "/foo/bar" :query)))
    (uri/assoc-query :frame-id "frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f" :kind "iframe")
    str)
"https://example.com/?src=/foo/bar&kind=iframe&frame-id=frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f"
"https://example.com/?src=/foo/bar&kind=iframe&frame-id=frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f"

(-> (uri/uri "https://example.com/")
    (assoc :query (str "src=" (normalize/percent-encode "/foo/bar" :query)))
    str)
;;=> "https://example.com/?src=/foo/bar"

(str domain "/a/iframe-viewer?src=" (url/url-encode src)
     "&frame-id=" frame-id "&kind=" (name kind))

(-> (uri/uri domain)
    (assoc :path "/a/iframe-viewer")
    (assoc-query :src src :frame-id frame-id :kind (name kind))
    str)

(normalize/normalize (uri/uri "https://dev.nextjournalusercontent.com:8888/a/iframe-viewer?src=%2Fdata%2FQmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication%252Fvnd.nextjournal.html%252Bhtml&frame-id=frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f&kind=iframe"))

#lambdaisland/uri "https://dev.nextjournalusercontent.com:8888/a/iframe-viewer?src=/data/QmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V?content-type=application%252Fvnd.nextjournal.html%252Bhtml&frame-id=frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f&kind=iframe"



(-> (uri/uri "https://example.com/")
    (uri/assoc-query :xxx "?#")
    (uri/assoc-query :yyy "?#")
    (uri/assoc-query :zzz "?#&=")
    str)

"https://example.com/?src=/foo/bar&kind=iframe&frame-id=frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f"

(-> (uri/uri "https://example.com/")
    (assoc :query (str "src=" (normalize/percent-encode "/foo/bar" :query)))
    str)
"https://example.com/?src=/foo/bar"
"https://example.com/?src=%2Ffoo%2Fbar"


(uri/query-map (uri/uri "?foo=%20%2B%26xxx%3D123"))
;;=> {:foo " +&xxx=123"}
(uri/query-map (normalize/normalize (uri/uri "?foo=%20%2B%26xxx%3D123")))
;;=> {:foo " +", :xxx "123"}

(-> (uri/uri "?foo=%20%2B%26xxx%3D123")
    normalize/normalize)
#lambdaisland/uri "?foo=%20+&xxx=123"


(normalize/percent-encode "+" :query)

;; => {:scheme "https"
;;     :user nil
;;     :password nil
;;     :host "example.com"
;;     :port nil
;;     :path "/"
;;     :query ""
;;     :fragment "hello"}

;; => {:scheme "https"
;;     :user nil
;;     :password nil
;;     :host "example.com"
;;     :port nil
;;     :path "/"
;;     :query "#hello"
;;     :fragment nil}

Parameter id must conform to #"^\d+$", but got "%2Fdata%2FQmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication%2Fvnd.nextjournal.html%2Bhtml" .
Parameter id must conform to clojure.core/uuid? , but got "%2Fdata%2FQmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication%2Fvnd.nextjournal.html%2Bhtml" .
Parameter id must conform to com.nextjournal.journal.params/matches-base58? , but got "%2Fdata%2FQmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication%2Fvnd.nextjournal.html%2Bhtml" .
Parameter id must conform to com.nextjournal.journal.params/matches-uuid? , but got "%2Fdata%2FQmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication%2Fvnd.nextjournal.html%2Bhtml" .

https://dev.nextjournalusercontent.com:8888/a/

(-> (uri/uri "https://example.com")
    (assoc :path "/a/iframe-viewer")
    (uri/assoc-query :frame-id 123
                     :kind "iframe"
                     :src "/data/QmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V?content-type=application/vnd.nextjournal.html+html")
    )
#lambdaisland/uri "https://example.com/a/iframe-viewer?src=/data/QmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication/vnd.nextjournal.html+html&kind=iframe&frame-id=123"