From f256b160bfdc1aed20d7917f03b2c26b980a06de Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 31 Aug 2023 06:25:31 -0400 Subject: [PATCH] url: handle unicode hostname if empty PR-URL: https://github.com/nodejs/node/pull/49396 Fixes: https://github.com/nodejs/node/issues/48759 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca --- src/node_url.cc | 2 +- test/parallel/test-url-format-whatwg.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node_url.cc b/src/node_url.cc index 149a926841b635..4d3c8108fa68dc 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -168,7 +168,7 @@ void BindingData::Format(const FunctionCallbackInfo& args) { out->hash = std::nullopt; } - if (unicode) { + if (unicode && out->has_hostname()) { out->host = ada::idna::to_unicode(out->get_hostname()); } diff --git a/test/parallel/test-url-format-whatwg.js b/test/parallel/test-url-format-whatwg.js index d1f0e0bcbddec2..bf9f8eaac63246 100644 --- a/test/parallel/test-url-format-whatwg.js +++ b/test/parallel/test-url-format-whatwg.js @@ -140,3 +140,8 @@ assert.strictEqual( url.format(new URL('http://user:pass@xn--0zwm56d.com:8080/path'), { unicode: true }), 'http://user:pass@测试.com:8080/path' ); + +assert.strictEqual( + url.format(new URL('tel:123')), + url.format(new URL('tel:123'), { unicode: true }) +);