Skip to content

Commit 773d1ba

Browse files
committed
url/literal: consider a query param already url-encoded if it contains a +
1 parent a1d2f23 commit 773d1ba

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

http-easy-lib/http-easy/private/url.rkt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@
122122
(get-output-string out))
123123

124124
(define (maybe-percent-encode s [encode uri-encode])
125-
(if (is-percent-encoded? s) s (encode s)))
125+
(if (is-percent-encoded? s encode) s (encode s)))
126126

127-
(define (is-percent-encoded? s)
127+
(define (is-percent-encoded? s [encode uri-encode])
128128
(define num-%-matches (length (regexp-match* #rx"%" s)))
129-
(and (> num-%-matches 0)
130-
(= num-%-matches (length (regexp-match* #px"%[a-fA-F0-9]{2}" s)))))
129+
(or (and (> num-%-matches 0)
130+
(= num-%-matches (length (regexp-match* #px"%[a-fA-F0-9]{2}" s))))
131+
(and (eq? encode form-urlencoded-encode)
132+
(regexp-match? #rx"[+]" s))))
131133

132134
(define (ipv6-host? s)
133135
(regexp-match? #rx"^[0-9a-fA-F:]*:[0-9a-fA-F:]*$" s))

http-easy-lib/info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#lang info
22

33
(define license 'BSD-3-Clause)
4-
(define version "0.8.1")
4+
(define version "0.8.2")
55
(define collection "net")
66
(define deps
77
'(["base" #:version "8.1.0.4"]

http-easy-test/net/http-easy/private/url.rkt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
("http://[email protected]:5100" . "http://[email protected]:5100")
6666
("http://example.com/a/b/c" . "http://example.com/a/b/c")
6767
("http://example.com/a%2Bb.mp3" . "http://example.com/a%2Bb.mp3")
68-
("http://example.com/a%2Bb.mp3?c=d+e" . "http://example.com/a%2Bb.mp3?c=d%2Be")
69-
("http://example.com/a%2Bb.mp3?c=d+e&f&g=h" . "http://example.com/a%2Bb.mp3?c=d%2Be&f&g=h")
68+
("http://example.com/a%2Bb.mp3?c=d+e" . "http://example.com/a%2Bb.mp3?c=d+e")
69+
("http://example.com/a%2Bb.mp3?c=d+e&f&g=h" . "http://example.com/a%2Bb.mp3?c=d+e&f&g=h")
7070
("a/b/c" . "a/b/c")
7171
("/a/b/c" . "/a/b/c")
7272
("/a;b;c" . "/a;b;c")))
@@ -95,7 +95,11 @@
9595
(for ([test (in-list tests)])
9696
(check-equal?
9797
(url/literal->string (string->url/literal test))
98-
(url->string (string->url test))))))
98+
(url->string (string->url test)))))
99+
100+
(test-case "examples"
101+
(let ([example "https://d12xz7rzfw7xh7.cloudfront.net/v1/download/episodes/original/43796816?a=en&eg=https%3A%2F%2Fapi.spreaker.com%2Fepisode%2F57758598&eu=https%3A%2F%2Fdts.podtrac.com%2Fredirect.mp3%2Fapi.spreaker.com%2Fdownload%2Fepisode%2F57758598%2Ftmp9u92imeh.mp3&p=3&q=9808638&f=559&r=128&t=3&u=11393707&o=2401044&d=2023-11-22&g=57758598&h=5937276&k=https%3A%2F%2Fwww.spreaker.com%2Fshow%2F5937276%2Fepisodes%2Ffeed&i=43796816&n=Petros+And+Money&b=%5B%22IAB6-7%22%2C%22IAB7-39%22%2C%22IAB11-4%22%2C%22IAB26%22%5D&c=%5B%22sports%22%5D&l=%5B%22hosting_plan_ihr%22%5D&m=%5B904294%2C904294%2C904294%2C1436858%2C1436858%2C1436858%2C1436858%2C1436858%2C1937091%2C1937091%2C1937091%5D&rr=4444444444444&fax=0.4&Expires=1732993926&Signature=XDgffPCg91Gd6ThNXoenP4axeBN2zEUK6Bs56F2Pw-LGE9XJuLPghg1f2etV1l6I3%7Ed7Ms12AQbkCp1vfkqleStA30fPDH2PpO1IKkw5k7PlSYyPCeb1DOc1No8s6KHn7C8DZ7swXjWEz5WGzrj6KtSgI%7EWMhQyiLuGxEmT9YBQViowMGeO7p1PNocQmT-SKo8WqMDMdzMmSXP2WQFYSk3AjFM2ukhGLzDkIcrNxy2ZRLGeUykF9ZWgNnGGAOfwsmx6n0IFQZcdDo2QpRKxOUjSBYOTxTo1Y716OYb73P59QurF%7El-jM7WLHgvFxWnJQHj9SwCnjSaCJgzDBlh%7EEDQ__&Key-Pair-Id=K1J2BR3INU6RYD"])
102+
(check-equal? (url/literal->string (string->url/literal example)) example))))
99103

100104
(test-suite
101105
"is-percent-encoded?"

0 commit comments

Comments
 (0)