From 209e7e3cff289da96257f4d0e10eb57658c8f4a8 Mon Sep 17 00:00:00 2001 From: Aidan Temple <15520814+aidant@users.noreply.github.com> Date: Mon, 14 Nov 2022 18:19:37 +0100 Subject: [PATCH] http: add debug log for ERR_UNESCAPED_CHARACTERS When encountering ERR_UNESCAPED_CHARACTERS on large applications it can be unclear which request has caused this error. Even when setting NODE_DEBUG=http there is no information about this error since it's thrown before any debug logs. This patch adds a debug log that contains the invalid path. PR-URL: https://github.com/nodejs/node/pull/45420 Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca --- lib/_http_client.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 19e9753c72467f..d62986da955955 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -178,8 +178,10 @@ function ClientRequest(input, options, cb) { if (options.path) { const path = String(options.path); - if (RegExpPrototypeExec(INVALID_PATH_REGEX, path) !== null) + if (RegExpPrototypeExec(INVALID_PATH_REGEX, path) !== null) { + debug('Path contains unescaped characters: "%s"', path); throw new ERR_UNESCAPED_CHARACTERS('Request path'); + } } if (protocol !== expectedProtocol) {