Skip to content

Commit

Permalink
url: handle unicode hostname if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Aug 28, 2023
1 parent 0409cdd commit 159c92c
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 @@ -208,7 +208,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 159c92c

Please sign in to comment.