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 }) +);