Skip to content

Commit

Permalink
url: handle unicode hostname if empty
Browse files Browse the repository at this point in the history
PR-URL: #49396
Fixes: #48759
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
anonrig authored and targos committed Nov 27, 2023
1 parent 67cb6f9 commit f256b16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void BindingData::Format(const FunctionCallbackInfo<Value>& args) {
out->hash = std::nullopt;
}

if (unicode) {
if (unicode && out->has_hostname()) {
out->host = ada::idna::to_unicode(out->get_hostname());
}

Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-url-format-whatwg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
);

0 comments on commit f256b16

Please sign in to comment.