@@ -44,6 +44,12 @@ test_that("url_build validates its input", {
4444 expect_snapshot(url_build(" abc" ), error = TRUE )
4545})
4646
47+ test_that(" decodes query params but not paths" , {
48+ url <- url_parse(" http://example.com/a%20b?q=a%20b" )
49+ expect_equal(url $ path , " /a%20b" )
50+ expect_equal(url $ query $ q , " a b" )
51+ })
52+
4753# modify url -------------------------------------------------------------
4854
4955test_that(" url_modify checks its inputs" , {
@@ -69,6 +75,14 @@ test_that("no arguments is idempotent", {
6975 expect_equal(url_modify(url ), url )
7076})
7177
78+ test_that(" can round-trip escaped components" , {
79+ url <- " https://example.com/a%20b"
80+ expect_equal(url_modify(url ), url )
81+
82+ url <- " https://example.com/?q=a%20b"
83+ expect_equal(url_modify(url ), url )
84+ })
85+
7286test_that(" can accept query as a string or list" , {
7387 url <- " http://test/"
7488
@@ -78,6 +92,14 @@ test_that("can accept query as a string or list", {
7892 expect_equal(url_modify(url , query = " " ), " http://test/" )
7993 expect_equal(url_modify(url , query = list ()), " http://test/" )
8094})
95+
96+ test_that(" automatically escapes query components" , {
97+ expect_equal(
98+ url_modify(" https://example.com" , query = list (q = " a b" )),
99+ " https://example.com/?q=a%20b"
100+ )
101+ })
102+
81103test_that(" checks various query formats" , {
82104 url <- " http://example.com"
83105
0 commit comments