├── .VERSION_PREFIX
├── .circleci
└── config.yml
├── .dir-locals.el
├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── bb.edn
├── bin
├── kaocha
└── proj
├── deps.edn
├── generate_docs
├── package.json
├── pom.xml
├── repl_sessions
├── encode.clj
├── merge_join.clj
├── poke.clj
├── round_trip_query_map.clj
├── uri_url_file_path.clj
└── walkthrough.clj
├── src
└── lambdaisland
│ ├── uri.cljc
│ └── uri
│ ├── normalize.cljc
│ ├── platform.clj
│ └── platform.cljs
├── test
└── lambdaisland
│ ├── test_runner.cljs
│ ├── uri
│ └── normalize_test.cljc
│ └── uri_test.cljc
└── tests.edn
/.VERSION_PREFIX:
--------------------------------------------------------------------------------
1 | 1.19
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 |
3 | orbs:
4 | kaocha: lambdaisland/kaocha@0.0.1
5 | clojure: lambdaisland/clojure@0.0.8
6 |
7 | commands:
8 | checkout_and_run:
9 | parameters:
10 | clojure_version:
11 | type: string
12 | steps:
13 | - checkout
14 | - clojure/with_cache:
15 | cache_version: << parameters.clojure_version >>
16 | steps:
17 | - run: clojure -e '(println (System/getProperty "java.runtime.name") (System/getProperty "java.runtime.version") "\nClojure" (clojure-version))'
18 | - run: npm install ws
19 | - kaocha/execute:
20 | args: "clj --reporter documentation --plugin cloverage --codecov"
21 | clojure_version: << parameters.clojure_version >>
22 | - kaocha/execute:
23 | args: "cljs --reporter documentation"
24 | clojure_version: << parameters.clojure_version >>
25 | - kaocha/upload_codecov:
26 | flags: clj
27 |
28 | jobs:
29 | java-17-clojure-1_10:
30 | executor: clojure/openjdk17
31 | steps: [{checkout_and_run: {clojure_version: "1.10.2"}}]
32 |
33 | java-11-clojure-1_10:
34 | executor: clojure/openjdk11
35 | steps: [{checkout_and_run: {clojure_version: "1.10.2"}}]
36 |
37 | java-9-clojure-1_10:
38 | executor: clojure/openjdk9
39 | steps: [{checkout_and_run: {clojure_version: "1.10.2"}}]
40 |
41 | java-8-clojure-1_10:
42 | executor: clojure/openjdk8
43 | steps: [{checkout_and_run: {clojure_version: "1.10.2"}}]
44 | test:
45 | parameters:
46 | os:
47 | type: executor
48 | clojure_version:
49 | type: string
50 | executor: << parameters.os >>
51 | steps:
52 | - checkout_and_run:
53 | clojure_version: << parameters.clojure_version >>
54 |
55 | babashka-tests:
56 | executor: clojure/openjdk8
57 | steps:
58 | - checkout
59 | - run:
60 | command: |
61 | curl -sLO https://raw.githubusercontent.com/babashka/babashka/master/install
62 | chmod +x install
63 | ./install --version 1.0.168
64 | bb test:bb
65 |
66 | workflows:
67 | kaocha_test:
68 | jobs:
69 | - babashka-tests
70 | - test:
71 | matrix:
72 | parameters:
73 | os: [clojure/openjdk19, clojure/openjdk17, clojure/openjdk11, clojure/openjdk8]
74 | clojure_version: ["1.10.3", "1.11.1"]
75 |
--------------------------------------------------------------------------------
/.dir-locals.el:
--------------------------------------------------------------------------------
1 | ((nil . ((cider-clojure-cli-global-options . "-A:dev:test"))))
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /classes
3 | /checkouts
4 | pom.xml.asc
5 | *.jar
6 | *.class
7 | /.lein-*
8 | /.nrepl-port
9 | .hgignore
10 | .hg/
11 | gh-pages
12 | .cljs_rhino_repl
13 | .cljs_node_repl
14 | out
15 | node_modules
16 | .cpcache
17 | package-lock.json
18 | .store
19 | .idea/
20 | .clj-kondo/
21 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: clojure
2 | install:
3 | - curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > my-lein
4 | - chmod +x my-lein
5 | - ./my-lein deps
6 | - ./my-lein --version
7 | script: ./my-lein test-all
8 | jdk:
9 | - oraclejdk8
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Unreleased
2 |
3 | ## Added
4 |
5 | ## Fixed
6 |
7 | ## Changed
8 |
9 | # 1.19.155 (2024-01-24 / a0d4895)
10 |
11 | ## Added
12 |
13 | - Support ipv6 literals
14 |
15 | # 1.18.150 (2024-01-24 / 1e4f0e2)
16 |
17 | ## Changed
18 |
19 | - `query-map` / `query-string->map`: when called with an `:into` collection, and
20 | no query params are present, then return the `:into` collection, rather than
21 | `nil`. If no explicit `:into` collection is provided, then retain the existing
22 | behavior of returning `nil` on blank input.
23 |
24 | # 1.17.141 (2024-01-23 / 96249d9)
25 |
26 | ## Added
27 |
28 | - Added functions for dealing with query strings as positional collections:
29 | `query-string->seq`, `seq->query-string`.
30 |
31 | ## Changed
32 |
33 | - `query-map`/`query-string->map` : return `:into` value on blank input
34 |
35 | # 1.16.134 (2023-10-10 / c0f16d8)
36 |
37 | ## Fixed
38 |
39 | - Do not truncate value of a query parameter pair when contains nested `=` characters
40 |
41 | # 1.15.125 (2023-03-30 / 5550226)
42 |
43 | ## Added
44 |
45 | - Adds `:into` option to define custom `clojure.lang.IPersistentMap` target data structure for `lambdaisland.uri/query-string->map`
46 |
47 | # 1.14.120 (2023-03-27 / a1da1b7)
48 |
49 | ## Fixed
50 |
51 | - Treat a backslash in the authority section as a delimiter which starts the
52 | path section (CVE-2023-28628, with thanks to @luigigubello for the report)
53 |
54 | # 1.13.95 (2022-01-28 / a9cbeff)
55 |
56 | ## Fixed
57 |
58 | - Fix a stack overflow in `normalize/char-seq` for really large query parameter
59 | values
60 |
61 | # 1.12.89 (2021-11-29 / 2118a75)
62 |
63 | ## Changed
64 |
65 | - Support `toString` on Babashka (requires recent `bb`)
66 |
67 | # 1.11.86 (2021-10-28 / 22c27af)
68 |
69 | ## Fixed
70 |
71 | - Fixed an issue in `lambdaisland.uri.normalize/normalize-query` which did
72 | not take into account utf-16 encoding.
73 |
74 | # 1.10.79 (2021-10-12 / d90c6a8)
75 |
76 | ## Changed
77 |
78 | - `lambdaisland.uri.normalize/normalize` now also normalizes the fragment.
79 |
80 | # 1.4.74 (2021-09-06 / e07f9fd)
81 |
82 | ## Added
83 |
84 | - `uri-str` as an explicit `lambdaisland.uri.URI` to string conversion
85 |
86 | ## Fixed
87 |
88 | - Fixed compatibility with Babashka/SCI. Note that on babashka we can't
89 | implement IFn or toString, so converting a `URI` back to a string needs to be
90 | done explicitly with `uri-str`, and it is not possible to use a URI as a
91 | function. (`(:path uri)` is ok, `(uri :path)` is not).
92 |
93 | # 1.4.70 (2021-05-31 / 76999dc)
94 |
95 | ## Added
96 |
97 | - Add `uri?` predicate.
98 |
99 | # 1.4.54 (2020-06-16 / 05a8a19)
100 |
101 | ## Fixed
102 |
103 | - Make query decoding handle `+` as space, so the conversion between maps and
104 | query strings correctly round trips.
105 | - Handle percent encoding of control characters (codepoints < 16)
106 | - make `lambdaisland.uri.platform/string->byte-seq` return unsigned bytes on
107 | both plaforms (clj/cljs)
108 |
109 | # 1.4.49 (2020-06-11 / ee48e58)
110 |
111 | ## Changed
112 |
113 | - Make `assoc-query` / `query-encode` encode spaces as "+" rather than "%20",
114 | which brings it in line to how most languages/libraries do it.
115 |
116 | # 1.3.45 (2020-05-01 / a04368b)
117 |
118 | ## Added
119 |
120 | - Added function for dealing with query strings as maps: `query-string->map`,
121 | `map->query-string`, `query-map`, `query-encode`, `assoc-query`,
122 | `assoc-query*`.
123 |
124 | ## Fixed
125 |
126 | - Fix query string normalization, for delimiter characters like `=` and `+`
127 | there is a semantic difference between the encoded and decoded form, when they
128 | are encoded in the input normalization should not decode them and vice versa
129 |
130 | # 1.2.1 (2020-02-23 / a992787)
131 |
132 | ## Changed
133 |
134 | - Remove dependencies on ClojureScript and data.json.
135 |
136 | # 1.2.0 (2020-02-17 / c0e1f1a)
137 |
138 | ## Added
139 |
140 | - `lambdaisland.uri.normalize/normalize`, for normalizing URI instances.
141 |
142 | ## Changed
143 |
144 | - Added type hints to avoid reflection (thanks @totakke!)
145 |
146 | # 1.1.0 (2017-04-25)
147 |
148 | ## Added
149 |
150 | - Predicate functions `absolute?` and `relative?`
151 |
152 | # 1.0.0 (2017-02-23)
153 |
154 | ## Added
155 |
156 | - Initial release, public vars: `uri`, `join`, `coerce`, `parse`, `edn-readers`
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Mozilla Public License Version 2.0
2 | ==================================
3 |
4 | 1. Definitions
5 | --------------
6 |
7 | 1.1. "Contributor"
8 | means each individual or legal entity that creates, contributes to
9 | the creation of, or owns Covered Software.
10 |
11 | 1.2. "Contributor Version"
12 | means the combination of the Contributions of others (if any) used
13 | by a Contributor and that particular Contributor's Contribution.
14 |
15 | 1.3. "Contribution"
16 | means Covered Software of a particular Contributor.
17 |
18 | 1.4. "Covered Software"
19 | means Source Code Form to which the initial Contributor has attached
20 | the notice in Exhibit A, the Executable Form of such Source Code
21 | Form, and Modifications of such Source Code Form, in each case
22 | including portions thereof.
23 |
24 | 1.5. "Incompatible With Secondary Licenses"
25 | means
26 |
27 | (a) that the initial Contributor has attached the notice described
28 | in Exhibit B to the Covered Software; or
29 |
30 | (b) that the Covered Software was made available under the terms of
31 | version 1.1 or earlier of the License, but not also under the
32 | terms of a Secondary License.
33 |
34 | 1.6. "Executable Form"
35 | means any form of the work other than Source Code Form.
36 |
37 | 1.7. "Larger Work"
38 | means a work that combines Covered Software with other material, in
39 | a separate file or files, that is not Covered Software.
40 |
41 | 1.8. "License"
42 | means this document.
43 |
44 | 1.9. "Licensable"
45 | means having the right to grant, to the maximum extent possible,
46 | whether at the time of the initial grant or subsequently, any and
47 | all of the rights conveyed by this License.
48 |
49 | 1.10. "Modifications"
50 | means any of the following:
51 |
52 | (a) any file in Source Code Form that results from an addition to,
53 | deletion from, or modification of the contents of Covered
54 | Software; or
55 |
56 | (b) any new file in Source Code Form that contains any Covered
57 | Software.
58 |
59 | 1.11. "Patent Claims" of a Contributor
60 | means any patent claim(s), including without limitation, method,
61 | process, and apparatus claims, in any patent Licensable by such
62 | Contributor that would be infringed, but for the grant of the
63 | License, by the making, using, selling, offering for sale, having
64 | made, import, or transfer of either its Contributions or its
65 | Contributor Version.
66 |
67 | 1.12. "Secondary License"
68 | means either the GNU General Public License, Version 2.0, the GNU
69 | Lesser General Public License, Version 2.1, the GNU Affero General
70 | Public License, Version 3.0, or any later versions of those
71 | licenses.
72 |
73 | 1.13. "Source Code Form"
74 | means the form of the work preferred for making modifications.
75 |
76 | 1.14. "You" (or "Your")
77 | means an individual or a legal entity exercising rights under this
78 | License. For legal entities, "You" includes any entity that
79 | controls, is controlled by, or is under common control with You. For
80 | purposes of this definition, "control" means (a) the power, direct
81 | or indirect, to cause the direction or management of such entity,
82 | whether by contract or otherwise, or (b) ownership of more than
83 | fifty percent (50%) of the outstanding shares or beneficial
84 | ownership of such entity.
85 |
86 | 2. License Grants and Conditions
87 | --------------------------------
88 |
89 | 2.1. Grants
90 |
91 | Each Contributor hereby grants You a world-wide, royalty-free,
92 | non-exclusive license:
93 |
94 | (a) under intellectual property rights (other than patent or trademark)
95 | Licensable by such Contributor to use, reproduce, make available,
96 | modify, display, perform, distribute, and otherwise exploit its
97 | Contributions, either on an unmodified basis, with Modifications, or
98 | as part of a Larger Work; and
99 |
100 | (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | for sale, have made, import, and otherwise transfer either its
102 | Contributions or its Contributor Version.
103 |
104 | 2.2. Effective Date
105 |
106 | The licenses granted in Section 2.1 with respect to any Contribution
107 | become effective for each Contribution on the date the Contributor first
108 | distributes such Contribution.
109 |
110 | 2.3. Limitations on Grant Scope
111 |
112 | The licenses granted in this Section 2 are the only rights granted under
113 | this License. No additional rights or licenses will be implied from the
114 | distribution or licensing of Covered Software under this License.
115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | Contributor:
117 |
118 | (a) for any code that a Contributor has removed from Covered Software;
119 | or
120 |
121 | (b) for infringements caused by: (i) Your and any other third party's
122 | modifications of Covered Software, or (ii) the combination of its
123 | Contributions with other software (except as part of its Contributor
124 | Version); or
125 |
126 | (c) under Patent Claims infringed by Covered Software in the absence of
127 | its Contributions.
128 |
129 | This License does not grant any rights in the trademarks, service marks,
130 | or logos of any Contributor (except as may be necessary to comply with
131 | the notice requirements in Section 3.4).
132 |
133 | 2.4. Subsequent Licenses
134 |
135 | No Contributor makes additional grants as a result of Your choice to
136 | distribute the Covered Software under a subsequent version of this
137 | License (see Section 10.2) or under the terms of a Secondary License (if
138 | permitted under the terms of Section 3.3).
139 |
140 | 2.5. Representation
141 |
142 | Each Contributor represents that the Contributor believes its
143 | Contributions are its original creation(s) or it has sufficient rights
144 | to grant the rights to its Contributions conveyed by this License.
145 |
146 | 2.6. Fair Use
147 |
148 | This License is not intended to limit any rights You have under
149 | applicable copyright doctrines of fair use, fair dealing, or other
150 | equivalents.
151 |
152 | 2.7. Conditions
153 |
154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | in Section 2.1.
156 |
157 | 3. Responsibilities
158 | -------------------
159 |
160 | 3.1. Distribution of Source Form
161 |
162 | All distribution of Covered Software in Source Code Form, including any
163 | Modifications that You create or to which You contribute, must be under
164 | the terms of this License. You must inform recipients that the Source
165 | Code Form of the Covered Software is governed by the terms of this
166 | License, and how they can obtain a copy of this License. You may not
167 | attempt to alter or restrict the recipients' rights in the Source Code
168 | Form.
169 |
170 | 3.2. Distribution of Executable Form
171 |
172 | If You distribute Covered Software in Executable Form then:
173 |
174 | (a) such Covered Software must also be made available in Source Code
175 | Form, as described in Section 3.1, and You must inform recipients of
176 | the Executable Form how they can obtain a copy of such Source Code
177 | Form by reasonable means in a timely manner, at a charge no more
178 | than the cost of distribution to the recipient; and
179 |
180 | (b) You may distribute such Executable Form under the terms of this
181 | License, or sublicense it under different terms, provided that the
182 | license for the Executable Form does not attempt to limit or alter
183 | the recipients' rights in the Source Code Form under this License.
184 |
185 | 3.3. Distribution of a Larger Work
186 |
187 | You may create and distribute a Larger Work under terms of Your choice,
188 | provided that You also comply with the requirements of this License for
189 | the Covered Software. If the Larger Work is a combination of Covered
190 | Software with a work governed by one or more Secondary Licenses, and the
191 | Covered Software is not Incompatible With Secondary Licenses, this
192 | License permits You to additionally distribute such Covered Software
193 | under the terms of such Secondary License(s), so that the recipient of
194 | the Larger Work may, at their option, further distribute the Covered
195 | Software under the terms of either this License or such Secondary
196 | License(s).
197 |
198 | 3.4. Notices
199 |
200 | You may not remove or alter the substance of any license notices
201 | (including copyright notices, patent notices, disclaimers of warranty,
202 | or limitations of liability) contained within the Source Code Form of
203 | the Covered Software, except that You may alter any license notices to
204 | the extent required to remedy known factual inaccuracies.
205 |
206 | 3.5. Application of Additional Terms
207 |
208 | You may choose to offer, and to charge a fee for, warranty, support,
209 | indemnity or liability obligations to one or more recipients of Covered
210 | Software. However, You may do so only on Your own behalf, and not on
211 | behalf of any Contributor. You must make it absolutely clear that any
212 | such warranty, support, indemnity, or liability obligation is offered by
213 | You alone, and You hereby agree to indemnify every Contributor for any
214 | liability incurred by such Contributor as a result of warranty, support,
215 | indemnity or liability terms You offer. You may include additional
216 | disclaimers of warranty and limitations of liability specific to any
217 | jurisdiction.
218 |
219 | 4. Inability to Comply Due to Statute or Regulation
220 | ---------------------------------------------------
221 |
222 | If it is impossible for You to comply with any of the terms of this
223 | License with respect to some or all of the Covered Software due to
224 | statute, judicial order, or regulation then You must: (a) comply with
225 | the terms of this License to the maximum extent possible; and (b)
226 | describe the limitations and the code they affect. Such description must
227 | be placed in a text file included with all distributions of the Covered
228 | Software under this License. Except to the extent prohibited by statute
229 | or regulation, such description must be sufficiently detailed for a
230 | recipient of ordinary skill to be able to understand it.
231 |
232 | 5. Termination
233 | --------------
234 |
235 | 5.1. The rights granted under this License will terminate automatically
236 | if You fail to comply with any of its terms. However, if You become
237 | compliant, then the rights granted under this License from a particular
238 | Contributor are reinstated (a) provisionally, unless and until such
239 | Contributor explicitly and finally terminates Your grants, and (b) on an
240 | ongoing basis, if such Contributor fails to notify You of the
241 | non-compliance by some reasonable means prior to 60 days after You have
242 | come back into compliance. Moreover, Your grants from a particular
243 | Contributor are reinstated on an ongoing basis if such Contributor
244 | notifies You of the non-compliance by some reasonable means, this is the
245 | first time You have received notice of non-compliance with this License
246 | from such Contributor, and You become compliant prior to 30 days after
247 | Your receipt of the notice.
248 |
249 | 5.2. If You initiate litigation against any entity by asserting a patent
250 | infringement claim (excluding declaratory judgment actions,
251 | counter-claims, and cross-claims) alleging that a Contributor Version
252 | directly or indirectly infringes any patent, then the rights granted to
253 | You by any and all Contributors for the Covered Software under Section
254 | 2.1 of this License shall terminate.
255 |
256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | end user license agreements (excluding distributors and resellers) which
258 | have been validly granted by You or Your distributors under this License
259 | prior to termination shall survive termination.
260 |
261 | ************************************************************************
262 | * *
263 | * 6. Disclaimer of Warranty *
264 | * ------------------------- *
265 | * *
266 | * Covered Software is provided under this License on an "as is" *
267 | * basis, without warranty of any kind, either expressed, implied, or *
268 | * statutory, including, without limitation, warranties that the *
269 | * Covered Software is free of defects, merchantable, fit for a *
270 | * particular purpose or non-infringing. The entire risk as to the *
271 | * quality and performance of the Covered Software is with You. *
272 | * Should any Covered Software prove defective in any respect, You *
273 | * (not any Contributor) assume the cost of any necessary servicing, *
274 | * repair, or correction. This disclaimer of warranty constitutes an *
275 | * essential part of this License. No use of any Covered Software is *
276 | * authorized under this License except under this disclaimer. *
277 | * *
278 | ************************************************************************
279 |
280 | ************************************************************************
281 | * *
282 | * 7. Limitation of Liability *
283 | * -------------------------- *
284 | * *
285 | * Under no circumstances and under no legal theory, whether tort *
286 | * (including negligence), contract, or otherwise, shall any *
287 | * Contributor, or anyone who distributes Covered Software as *
288 | * permitted above, be liable to You for any direct, indirect, *
289 | * special, incidental, or consequential damages of any character *
290 | * including, without limitation, damages for lost profits, loss of *
291 | * goodwill, work stoppage, computer failure or malfunction, or any *
292 | * and all other commercial damages or losses, even if such party *
293 | * shall have been informed of the possibility of such damages. This *
294 | * limitation of liability shall not apply to liability for death or *
295 | * personal injury resulting from such party's negligence to the *
296 | * extent applicable law prohibits such limitation. Some *
297 | * jurisdictions do not allow the exclusion or limitation of *
298 | * incidental or consequential damages, so this exclusion and *
299 | * limitation may not apply to You. *
300 | * *
301 | ************************************************************************
302 |
303 | 8. Litigation
304 | -------------
305 |
306 | Any litigation relating to this License may be brought only in the
307 | courts of a jurisdiction where the defendant maintains its principal
308 | place of business and such litigation shall be governed by laws of that
309 | jurisdiction, without reference to its conflict-of-law provisions.
310 | Nothing in this Section shall prevent a party's ability to bring
311 | cross-claims or counter-claims.
312 |
313 | 9. Miscellaneous
314 | ----------------
315 |
316 | This License represents the complete agreement concerning the subject
317 | matter hereof. If any provision of this License is held to be
318 | unenforceable, such provision shall be reformed only to the extent
319 | necessary to make it enforceable. Any law or regulation which provides
320 | that the language of a contract shall be construed against the drafter
321 | shall not be used to construe this License against a Contributor.
322 |
323 | 10. Versions of the License
324 | ---------------------------
325 |
326 | 10.1. New Versions
327 |
328 | Mozilla Foundation is the license steward. Except as provided in Section
329 | 10.3, no one other than the license steward has the right to modify or
330 | publish new versions of this License. Each version will be given a
331 | distinguishing version number.
332 |
333 | 10.2. Effect of New Versions
334 |
335 | You may distribute the Covered Software under the terms of the version
336 | of the License under which You originally received the Covered Software,
337 | or under the terms of any subsequent version published by the license
338 | steward.
339 |
340 | 10.3. Modified Versions
341 |
342 | If you create software not governed by this License, and you want to
343 | create a new license for such software, you may create and use a
344 | modified version of this License if you rename the license and remove
345 | any references to the name of the license steward (except to note that
346 | such modified license differs from this License).
347 |
348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | Licenses
350 |
351 | If You choose to distribute Source Code Form that is Incompatible With
352 | Secondary Licenses under the terms of this version of the License, the
353 | notice described in Exhibit B of this License must be attached.
354 |
355 | Exhibit A - Source Code Form License Notice
356 | -------------------------------------------
357 |
358 | This Source Code Form is subject to the terms of the Mozilla Public
359 | License, v. 2.0. If a copy of the MPL was not distributed with this
360 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
361 |
362 | If it is not possible or desirable to put the notice in a particular
363 | file, then You may include the notice in a location (such as a LICENSE
364 | file in a relevant directory) where a recipient would be likely to look
365 | for such a notice.
366 |
367 | You may add additional accurate notices of copyright ownership.
368 |
369 | Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ---------------------------------------------------------
371 |
372 | This Source Code Form is "Incompatible With Secondary Licenses", as
373 | defined by the Mozilla Public License, v. 2.0.
374 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # lambdaisland/uri
2 |
3 |
4 | [](https://circleci.com/gh/lambdaisland/uri) [](https://cljdoc.org/d/lambdaisland/uri) [](https://clojars.org/lambdaisland/uri)
5 | [](https://babashka.org)
6 |
7 |
8 | A pure Clojure/ClojureScript URI library.
9 |
10 | Key features
11 |
12 | - 100% cross-platform `.cljc`
13 | - RFC compliant joining of URIs
14 | - relative URIs as first class citizens
15 |
16 |
17 | ## Lambda Island Open Source
18 |
19 |
20 |
21 |
22 |
23 | uri is part of a growing collection of quality Clojure libraries created and maintained
24 | by the fine folks at [Gaiwan](https://gaiwan.co).
25 |
26 | Pay it forward by [becoming a backer on our Open Collective](http://opencollective.com/lambda-island),
27 | so that we may continue to enjoy a thriving Clojure ecosystem.
28 |
29 | You can find an overview of our projects at [lambdaisland/open-source](https://github.com/lambdaisland/open-source).
30 |
31 |
32 |
33 |
34 |
35 |
36 | ## Rationale
37 |
38 | There are a number of Clojure libraries for working with URI/URLs (see
39 | [Similar projects](#similar-projects) below). They all rely to some degree on
40 | `java.net.URI` or `java.net.URL`. This lib provides a pure-Clojure/ClojureScript
41 | alternative.
42 |
43 | See the [announcement blog post](https://lambdaisland.com/blog/27-02-2017-announcing-lambdaisland-uri)
44 |
45 | ## Installation
46 |
47 | To install, add the following dependency to your project or build file:
48 |
49 | deps.edn:
50 |
51 | ``` clojure
52 | lambdaisland/uri {:mvn/version "1.19.155"}
53 | ```
54 |
55 | project.clj
56 |
57 | ``` clojure
58 | [lambdaisland/uri "1.19.155"]
59 | ```
60 |
61 | ## Usage
62 |
63 | ``` clojure
64 | (require '[lambdaisland.uri :refer [uri join]])
65 |
66 |
67 | ;; uri :: String -> lambdaisland.uri.URI
68 | (uri "//example.com/foo/bar")
69 | ;;=> #lambdaisland/uri "//example.com/foo/bar"
70 |
71 |
72 | ;; A URI is a record, use assoc to update specific parts
73 | ;; Use `str` if you want the URI back as a string
74 | (str
75 | (assoc (uri "//example.com/foo/bar")
76 | :scheme "https"
77 | :user "arne"
78 | :password "supersecret"
79 | :host "lambdaisland.com"
80 | :port "3333"
81 | :path "/hello/world"
82 | :query "q=5"
83 | :fragment "section1"))
84 | ;;=> "https://arne:supersecret@lambdaisland.com:3333/hello/world?q=5#section1"
85 |
86 |
87 | ;; RFC compliant joining of relative URIs
88 | (join "//example.com/foo/bar" "./~arne/site/" "../foo.png")
89 | ;;=> #lambdaisland/uri "//example.com/foo/~arne/foo.png"
90 |
91 |
92 | ;; Arguments to `join` are coerced, you can pass strings, java.net.URI, or any x
93 | ;; for which `(str x)` returns a URI string.
94 | (join (java.net.URI. "http://example.com/foo/bar") (uri "./~arne/site/") "../foo.png")
95 | ;;=> #lambdaisland/uri "http://example.com/foo/~arne/foo.png"
96 |
97 |
98 | ;; URI implements IFn for keyword based lookup, so it's fully
99 | ;; interface-compatible with Clojure maps.
100 | (:path (uri "http://example.com/foo/bar"))
101 |
102 | ;; Provide custom ordering for query-map
103 | ;; clj -Sdeps '{:deps {org.flatland/ordered {:mvn/version "1.5.7"}}}'
104 | (require '[lambdaisland.uri :refer [query-map]]
105 | '[flatland.ordered.map :refer [ordered-map]])
106 | (keys (query-map "http://example.com?a=1&b=2&c=3&d=4&e=5&f=6&g=7&h=8&i=9"
107 | {:into (ordered-map)}))
108 | => (:a :b :c :d :e :f :g :h :i)
109 |
110 | ;; Instances of URI are printed with a #lambdaisland/uri reader tag. To read
111 | ;; them back from EDN, use the provided readers.
112 | (require '[clojure.edn :as edn])
113 |
114 | (edn/read-string
115 | {:readers lambdaisland.uri/edn-readers}
116 | "#lambdaisland/uri \"http://example.com/foo/~arne/foo.png\"")
117 | ```
118 |
119 | [Full API docs are on Cljdoc](https://cljdoc.org/d/lambdaisland/uri)
120 |
121 | ## Babashka-specific caveats (also applies to SCI)
122 |
123 | Instances of URI implement the `toString` method, so calling `(str uri)` gives
124 | you the URI back as a string. They also implement the `IFn` interfaces so they
125 | are callable the way maps are.
126 |
127 | On babashka implementing interfaces or overriding Object methods is not
128 | supported. As an alternative to `clojure.core/str` you can use
129 | `lambdaisland.uri/uri-str`. As an alternative to using the URI as a function, use the keyword as a function, or use `clojure.core/get`
130 |
131 | ``` clojure
132 | ;; clojure / clojurescript
133 | (str uri) ;; "https://example.com"
134 | (uri :host) ;; "example.com"
135 |
136 | ;; bb
137 | (str uri) ;; "{:scheme "https", :domain "example.com", :path ...}"
138 | (uri :host) ;; nil
139 |
140 | (uri/uri-str uri) ;; "https://example.com"
141 | (:host uri) ;; "example.com"
142 | (get uri :host) ;; "example.com"
143 | ```
144 |
145 | ## Similar projects
146 |
147 | * [exploding-fish](https://github.com/wtetzner/exploding-fish)
148 | I was not aware at the time of creating lambdaisland/uri of exploding fish. It
149 | is the most mature pure-Clojure URI lib out there. It does not provide
150 | ClojureScript support.
151 | * [cemerick/url](https://github.com/cemerick/url)
152 | Cross platform (cljx), Clojure version uses `java.net.URL`.
153 | * [michaelklishin/urly](https://github.com/michaelklishin/urly)
154 | Based on `java.net.URI`.
155 | * [codonnell/uri](https://github.com/codonnell/uri)
156 | Based on `java.net.URI`.
157 |
158 | ## Further reading
159 |
160 | [RFC3986 Uniform Resource Identifier (URI): Generic Syntax](https://www.ietf.org/rfc/rfc3986.txt)
161 |
162 | This library implements the algorithm specified in [Section 5.2](https://tools.ietf.org/html/rfc3986#section-5.2) of that RFC.
163 |
164 | It has been tested against [this list of test cases compiled by the W3C](https://www.w3.org/2004/04/uri-rel-test.html).
165 |
166 |
167 | ## Contributing
168 |
169 | Everyone has a right to submit patches to uri, and thus become a contributor.
170 |
171 | Contributors MUST
172 |
173 | - adhere to the [LambdaIsland Clojure Style Guide](https://nextjournal.com/lambdaisland/clojure-style-guide)
174 | - write patches that solve a problem. Start by stating the problem, then supply a minimal solution. `*`
175 | - agree to license their contributions as MPL 2.0.
176 | - not break the contract with downstream consumers. `**`
177 | - not break the tests.
178 |
179 | Contributors SHOULD
180 |
181 | - update the CHANGELOG and README.
182 | - add tests for new functionality.
183 |
184 | If you submit a pull request that adheres to these rules, then it will almost
185 | certainly be merged immediately. However some things may require more
186 | consideration. If you add new dependencies, or significantly increase the API
187 | surface, then we need to decide if these changes are in line with the project's
188 | goals. In this case you can start by [writing a pitch](https://nextjournal.com/lambdaisland/pitch-template),
189 | and collecting feedback on it.
190 |
191 | `*` This goes for features too, a feature needs to solve a problem. State the problem it solves, then supply a minimal solution.
192 |
193 | `**` As long as this project has not seen a public release (i.e. is not on Clojars)
194 | we may still consider making breaking changes, if there is consensus that the
195 | changes are justified.
196 |
197 |
198 |
199 | ## License
200 |
201 | Copyright © 2017-2021 Arne Brasseur and Contributors
202 |
203 | Licensed under the term of the Mozilla Public License 2.0, see LICENSE.
204 |
205 |
--------------------------------------------------------------------------------
/bb.edn:
--------------------------------------------------------------------------------
1 | {:deps
2 | {lambdaisland/open-source {:git/url "https://github.com/lambdaisland/open-source"
3 | :git/sha "7ce125cbd14888590742da7ab3b6be9bba46fc7a"}
4 | current/project {:local/root "."}}
5 |
6 | :tasks
7 | {test:clj {:doc "Run Clojure JVM tests"
8 | :task (shell "bin/kaocha")}
9 |
10 | test:bb {:doc "Run babashka tests"
11 | :extra-paths ["test"]
12 | :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"}}
13 | :requires ([lambdaisland.uri-test])
14 | :task (let [{:keys [error fail]} (clojure.test/run-tests 'lambdaisland.uri-test)]
15 | (when (pos? (+ error fail))
16 | (throw (ex-info "Tests failed" {:babashka/exit 1}))))}}}
17 |
--------------------------------------------------------------------------------
/bin/kaocha:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | [[ -d "node_modules/ws" ]] || npm install ws
4 |
5 | clojure -A:dev:test -m kaocha.runner "$@"
6 |
--------------------------------------------------------------------------------
/bin/proj:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bb
2 |
3 | (ns proj (:require [lioss.main :as lioss]))
4 |
5 | (lioss/main
6 | {:license :mpl
7 | :group-id "lambdaisland"
8 | :inception-year 2017
9 | :description "A pure Clojure/ClojureScript URI library."})
10 |
11 |
12 | ;; Local Variables:
13 | ;; mode:clojure
14 | ;; End:
15 |
--------------------------------------------------------------------------------
/deps.edn:
--------------------------------------------------------------------------------
1 | {:paths ["src"]
2 | :deps {org.clojure/clojure {:mvn/version "1.11.1"}}
3 |
4 | :aliases
5 | {:dev {}
6 | :test
7 | {:extra-paths ["test"]
8 | :extra-deps
9 | {org.clojure/clojurescript {:mvn/version "1.11.121"}
10 | lambdaisland/kaocha {:mvn/version "1.87.1366"}
11 | com.lambdaisland/kaocha-cljs {:mvn/version "1.5.154"}
12 | lambdaisland/kaocha-junit-xml {:mvn/version "1.17.101"}
13 | org.clojure/test.check {:mvn/version "1.1.1"}}}}}
14 |
--------------------------------------------------------------------------------
/generate_docs:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | export AUTODOC_CMD="lein with-profile +codox codox"
4 |
5 | \curl -sSL https://raw.githubusercontent.com/plexus/autodoc/master/autodoc.sh | bash
6 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "ws": "^8.16.0"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | lambdaisland
5 | uri
6 | 1.19.155
7 | uri
8 | A pure Clojure/ClojureScript URI library.
9 | https://github.com/lambdaisland/uri
10 | 2017
11 |
12 | Lambda Island
13 | https://lambdaisland.com
14 |
15 |
16 | UTF-8
17 |
18 |
19 |
20 | MPL-2.0
21 | https://www.mozilla.org/media/MPL/2.0/index.txt
22 |
23 |
24 |
25 | https://github.com/lambdaisland/uri
26 | scm:git:git://github.com/lambdaisland/uri.git
27 | scm:git:ssh://git@github.com/lambdaisland/uri.git
28 | 1b0a2d0d6845af5dd45d3f8685d1db9a20ca56ef
29 |
30 |
31 |
32 | org.clojure
33 | clojure
34 | 1.11.1
35 |
36 |
37 |
38 | src
39 |
40 |
41 | src
42 |
43 |
44 |
45 |
46 | org.apache.maven.plugins
47 | maven-compiler-plugin
48 | 3.8.1
49 |
50 | 1.8
51 | 1.8
52 |
53 |
54 |
55 | org.apache.maven.plugins
56 | maven-jar-plugin
57 | 3.2.0
58 |
59 |
60 |
61 | 1b0a2d0d6845af5dd45d3f8685d1db9a20ca56ef
62 |
63 |
64 |
65 |
66 |
67 | org.apache.maven.plugins
68 | maven-gpg-plugin
69 | 1.6
70 |
71 |
72 | sign-artifacts
73 | verify
74 |
75 | sign
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | clojars
85 | https://repo.clojars.org/
86 |
87 |
88 |
89 |
90 | clojars
91 | Clojars repository
92 | https://clojars.org/repo
93 |
94 |
95 |
--------------------------------------------------------------------------------
/repl_sessions/encode.clj:
--------------------------------------------------------------------------------
1 | (ns encode
2 | (:require [lambdaisland.uri :as uri]
3 | [lambdaisland.uri.normalize :as normalize]))
4 |
5 | (-> (uri/uri "https://example.com/")
6 | (assoc :query (str "src=" (normalize/percent-encode "/foo/bar" :query)))
7 | (uri/assoc-query :frame-id "frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f" :kind "iframe")
8 | str)
9 | "https://example.com/?src=/foo/bar&kind=iframe&frame-id=frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f"
10 | "https://example.com/?src=/foo/bar&kind=iframe&frame-id=frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f"
11 |
12 | (-> (uri/uri "https://example.com/")
13 | (assoc :query (str "src=" (normalize/percent-encode "/foo/bar" :query)))
14 | str)
15 | ;;=> "https://example.com/?src=/foo/bar"
16 |
17 | (str domain "/a/iframe-viewer?src=" (url/url-encode src)
18 | "&frame-id=" frame-id "&kind=" (name kind))
19 |
20 | (-> (uri/uri domain)
21 | (assoc :path "/a/iframe-viewer")
22 | (assoc-query :src src :frame-id frame-id :kind (name kind))
23 | str)
24 |
25 | (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"))
26 |
27 | #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"
28 |
29 |
30 |
31 | (-> (uri/uri "https://example.com/")
32 | (uri/assoc-query :xxx "?#")
33 | (uri/assoc-query :yyy "?#")
34 | (uri/assoc-query :zzz "?#&=")
35 | str)
36 |
37 | "https://example.com/?src=/foo/bar&kind=iframe&frame-id=frame-1d3ba257-4c55-48a5-8011-5d1aba5c240f"
38 |
39 | (-> (uri/uri "https://example.com/")
40 | (assoc :query (str "src=" (normalize/percent-encode "/foo/bar" :query)))
41 | str)
42 | "https://example.com/?src=/foo/bar"
43 | "https://example.com/?src=%2Ffoo%2Fbar"
44 |
45 |
46 | (uri/query-map (uri/uri "?foo=%20%2B%26xxx%3D123"))
47 | ;;=> {:foo " +&xxx=123"}
48 | (uri/query-map (normalize/normalize (uri/uri "?foo=%20%2B%26xxx%3D123")))
49 | ;;=> {:foo " +", :xxx "123"}
50 |
51 | (-> (uri/uri "?foo=%20%2B%26xxx%3D123")
52 | normalize/normalize)
53 | #lambdaisland/uri "?foo=%20+&xxx=123"
54 |
55 |
56 | (normalize/percent-encode "+" :query)
57 |
58 | ;; => {:scheme "https"
59 | ;; :user nil
60 | ;; :password nil
61 | ;; :host "example.com"
62 | ;; :port nil
63 | ;; :path "/"
64 | ;; :query ""
65 | ;; :fragment "hello"}
66 |
67 | ;; => {:scheme "https"
68 | ;; :user nil
69 | ;; :password nil
70 | ;; :host "example.com"
71 | ;; :port nil
72 | ;; :path "/"
73 | ;; :query "#hello"
74 | ;; :fragment nil}
75 |
76 | Parameter id must conform to #"^\d+$", but got "%2Fdata%2FQmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication%2Fvnd.nextjournal.html%2Bhtml" .
77 | Parameter id must conform to clojure.core/uuid? , but got "%2Fdata%2FQmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication%2Fvnd.nextjournal.html%2Bhtml" .
78 | Parameter id must conform to com.nextjournal.journal.params/matches-base58? , but got "%2Fdata%2FQmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication%2Fvnd.nextjournal.html%2Bhtml" .
79 | Parameter id must conform to com.nextjournal.journal.params/matches-uuid? , but got "%2Fdata%2FQmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication%2Fvnd.nextjournal.html%2Bhtml" .
80 |
81 | https://dev.nextjournalusercontent.com:8888/a/
82 |
83 | (-> (uri/uri "https://example.com")
84 | (assoc :path "/a/iframe-viewer")
85 | (uri/assoc-query :frame-id 123
86 | :kind "iframe"
87 | :src "/data/QmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V?content-type=application/vnd.nextjournal.html+html")
88 | )
89 | #lambdaisland/uri "https://example.com/a/iframe-viewer?src=/data/QmfFEyfAfGq3siNJyVxMcddyxtHtRjFKqfm81Nw5wiML3V%3Fcontent-type%3Dapplication/vnd.nextjournal.html+html&kind=iframe&frame-id=123"
90 |
--------------------------------------------------------------------------------
/repl_sessions/merge_join.clj:
--------------------------------------------------------------------------------
1 | (require '[lambdaisland.uri :as uri])
2 |
3 | (-> (uri/uri "https://my.service/some-context/?api_key=123")
4 | (update :path str "some-resource"))
5 |
6 | (defn uri-merge [& uris]
7 | (let [uri-maps (->> uris (map uri/uri) (map #(into {} (filter (comp some? val)) %)))
8 | merged-path (some->> uris (keep :path) seq (apply uri/join) :path)]
9 | (-> (apply merge uri-maps)
10 | (assoc :path merged-path)
11 | uri/map->URI)))
12 |
13 | (str (uri-merge "http://localhost:3303/hello-world"
14 | "https://en.wikipedia.org/wiki/VT100#Variants"))
15 | ;; => "https://en.wikipedia.org:3303#Variants"
16 |
17 | (def endpoint "https://my.service/some-context/")
18 | (def api-key "123")
19 |
20 | (defn api-uri [& segments]
21 | (-> (apply uri/join endpoint segments)
22 | (assoc :query (str "api-key=123"))))
23 |
24 | (api-uri endpoint "some-resource")
25 | ;; => "https://my.service/some-context/some-resource?api-key=123"
26 |
--------------------------------------------------------------------------------
/repl_sessions/poke.clj:
--------------------------------------------------------------------------------
1 | (ns repl-sessions.poke
2 | (:require [lambdaisland.uri :as uri]
3 | [lambdaisland.uri.normalize :as norm]))
4 |
5 | (:fragment (norm/normalize (uri/map->URI {:fragment "'#'schön"})))
6 | "'%23'sch%C3%B6n"
7 |
8 | (norm/normalize-fragment "schön")
9 | ;; => "sch%C3%B6n"
10 |
11 |
12 | (uri/map->query-string {:foo "bar"});; => "foo=bar"
13 | (uri/map->query-string {:foo/baz "bar"});; => "foo/baz=bar"
14 | (uri/query-string->map "foo=bar");; => {:foo "bar"}
15 | (uri/query-string->map "%3Afoo=bar" {:keywordize? false});; => {":foo" "bar"}
16 |
17 | ;; => #::foo{:baz "bar"}
18 |
19 | ;; => #:foo{:baz "bar"}
20 |
21 | (let [{:keys [scheme host port]} (uri/uri "https://foo.bar:8080")]
22 | )
23 |
24 | (:query (uri/uri "http://example.com?hello"))
25 |
26 | (uri/map->query-string {:foo "", :bar nil})
27 | ;; => "foo="
28 |
--------------------------------------------------------------------------------
/repl_sessions/round_trip_query_map.clj:
--------------------------------------------------------------------------------
1 | (ns round-trip-query-map
2 | (:require [lambdaisland.uri :as uri]
3 | [lambdaisland.uri.normalize :as norm]
4 | [lambdaisland.uri.platform :as platform]
5 | [clojure.test.check.generators :as gen]
6 | [clojure.test.check.properties :as prop]
7 | [clojure.test.check :as check]
8 | [clojure.string :as str]))
9 |
10 | (def query-map-gen
11 | (gen/map gen/keyword
12 | gen/string))
13 |
14 | (check/quick-check 10000
15 | (prop/for-all [q query-map-gen]
16 | (let [res (-> q
17 | uri/map->query-string
18 | uri/query-string->map)]
19 | (or (and (empty? q) (empty? res)) ;; (= nil {})
20 | (= q res)))))
21 |
22 | (def query-string-part-gen (gen/such-that (complement (partial some #{\& \= \% \space})) gen/string))
23 | (def query-string-gen (gen/fmap
24 | (fn [parts]
25 | (str/join
26 | "&"
27 | (map (fn [[k v]] (str k "=" v)) parts)))
28 | (gen/list (gen/tuple (gen/such-that seq query-string-part-gen)
29 | (gen/such-that seq query-string-part-gen)))))
30 |
31 | (check/quick-check 100
32 | (prop/for-all [q query-string-gen]
33 | (let [res (-> q
34 | uri/query-string->map
35 | uri/map->query-string
36 | norm/percent-decode)]
37 | (or (and (empty? q) (empty? res)) ;; (= nil {})
38 | (= q res)))))
39 | {:shrunk {:total-nodes-visited 327, :depth 36, :pass? false, :result false, :result-data nil, :time-shrinking-ms 65, :smallest [" = &= &