Skip to content

Commit c430dbe

Browse files
committed
Accept more characters for crates names/versions in path
#33 This commit fix a bug where using characters like "+" in crates names was causing issues with Meuse.
1 parent c7df194 commit c430dbe

5 files changed

Lines changed: 43 additions & 12 deletions

File tree

src/meuse/api/crate.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(ns meuse.api.crate)
2+
3+
;; the regex for the crates names and versions in path
4+
(def crate-regex #"[a-zA-Z0-9~._+~-]+")
5+
6+
(def crate-name-path [crate-regex :crate-name])
7+
(def crate-version-path [crate-regex :crate-version])

src/meuse/api/crate/http.clj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns meuse.api.crate.http
2-
(:require [meuse.api.default :as default]))
2+
(:require [meuse.api.default :as default]
3+
[meuse.api.crate :as mac]))
34

45
(def skip-auth
56
"Skip token auth for these calls."
@@ -8,12 +9,12 @@
89
(def crates-routes
910
{#"/new/?" {:put ::new}
1011
#"/?" {:get ::search}
11-
["/" :crate-name #"/owners/?"] {:put ::add-owner}
12-
["/" :crate-name #"/owners/?"] {:delete ::remove-owner}
13-
["/" :crate-name #"/owners/?"] {:get ::list-owners}
14-
["/" :crate-name "/" :crate-version "/yank"] {:delete ::yank}
15-
["/" :crate-name "/" :crate-version "/unyank"] {:put ::unyank}
16-
["/" :crate-name "/" :crate-version "/download"] {:get ::download}
12+
["/" mac/crate-name-path #"/owners/?"] {:put ::add-owner}
13+
["/" mac/crate-name-path #"/owners/?"] {:delete ::remove-owner}
14+
["/" mac/crate-name-path #"/owners/?"] {:get ::list-owners}
15+
["/" mac/crate-name-path "/" mac/crate-version-path "/yank"] {:delete ::yank}
16+
["/" mac/crate-name-path "/" mac/crate-version-path "/unyank"] {:put ::unyank}
17+
["/" mac/crate-name-path "/" mac/crate-version-path "/download"] {:get ::download}
1718
#"/andouillette" ::andouillette})
1819

1920
(defmulti crates-api!

src/meuse/api/meuse/http.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns meuse.api.meuse.http
2-
(:require [meuse.api.default :as default]))
2+
(:require [meuse.api.crate :as mac]
3+
[meuse.api.default :as default]))
34

45
(def skip-auth
56
"Skip token auth for these calls."
@@ -17,7 +18,7 @@
1718
#"/token/?" {:get ::list-tokens}
1819
[#"/token/?"] {:delete ::delete-token}
1920
#"/crate/?" {:get ::list-crates}
20-
[#"/crate/?" :name] {:get ::get-crate}
21+
[#"/crate/?" [mac/crate-regex :name]] {:get ::get-crate}
2122
#"/check/?" {:get ::check-crates}
2223
#"/statistics/?" {:get ::statistics}})
2324

src/meuse/api/mirror/http.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
(ns meuse.api.mirror.http
2-
(:require [meuse.api.default :as default]))
2+
(:require [meuse.api.crate :as mac]
3+
[meuse.api.default :as default]))
34

45
(def skip-auth
56
"Skip token auth for these calls."
67
#{:download})
78

89
(def mirror-routes
9-
{["/" :crate-name "/" :crate-version "/download"] {:get ::download}
10-
["/" :crate-name "/" :crate-version "/cache"] {:post ::cache}})
10+
{["/" mac/crate-name-path "/" mac/crate-version-path "/download"] {:get ::download}
11+
["/" mac/crate-name-path "/" mac/crate-version-path "/cache"] {:post ::cache}})
1112

1213
(defmulti mirror-api!
1314
"Handle crates.io api calls"

test/meuse/api/crate_test.clj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(ns meuse.api.crate-test
2+
(:require [clojure.test :refer :all]
3+
[meuse.api.crate :as mac]))
4+
5+
(deftest crate-regex-test
6+
(are [v] (re-matches mac/crate-regex v)
7+
"foo"
8+
"foo-bar"
9+
"foo_bar"
10+
"foo-1.1.2"
11+
"1.1.2"
12+
"1.1.2-alpha"
13+
"1.1.2_alpha"
14+
"1.1.2+3.4.5"
15+
"1.1.2~foo"
16+
"1.1.2~_-+134.1")
17+
(are [v] (not (re-matches mac/crate-regex v))
18+
"foo bar"
19+
"foo%bar"
20+
"foo/bar"
21+
"foo\\bar"))

0 commit comments

Comments
 (0)