From 9f095b2ebebb931535bcad60f0a4a860a53ac84b Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 23 Dec 2024 11:01:39 -0600 Subject: [PATCH] Use a stricter definition of header names To make it less likely that URLs (or other non-header contents) are mangled. This only affects verobse printing (including `req_dry_run()`) so it shouldn't cause problems even if it's not 100% accurate. Fixes #567 --- R/req-options.R | 2 +- tests/testthat/test-req-perform.R | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/R/req-options.R b/R/req-options.R index 08939d24..4e8fd040 100644 --- a/R/req-options.R +++ b/R/req-options.R @@ -207,7 +207,7 @@ verbose_header <- function(prefix, x, redact = TRUE, to_redact = NULL) { lines <- unlist(strsplit(x, "\r?\n", useBytes = TRUE)) for (line in lines) { - if (grepl(":", line, fixed = TRUE)) { + if (grepl("^[-a-zA-z0-9]+:", line)) { header <- headers_redact(as_headers(line), redact, to_redact = to_redact) cli::cat_line(prefix, cli::style_bold(names(header)), ": ", header) } else { diff --git a/tests/testthat/test-req-perform.R b/tests/testthat/test-req-perform.R index 0dbafcc5..9576b25c 100644 --- a/tests/testthat/test-req-perform.R +++ b/tests/testthat/test-req-perform.R @@ -225,3 +225,8 @@ test_that("authorization headers are redacted", { req_dry_run() }) }) + +test_that("doen't add space to urls (#567)", { + req <- request("https://example.com/test:1:2") + expect_output(req_dry_run(req), "test:1:2") +})