Skip to content

Commit

Permalink
Use a stricter definition of header names
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hadley committed Dec 23, 2024
1 parent 9db8f7e commit 9f095b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/req-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-req-perform.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

0 comments on commit 9f095b2

Please sign in to comment.