Skip to content

Commit

Permalink
src: modify code for empty string
Browse files Browse the repository at this point in the history
PR-URL: nodejs#49336
Refs: nodejs#49097
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
  • Loading branch information
pluris authored and alexfernandez committed Nov 1, 2023
1 parent 1b32de7 commit a3ae7a5
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void BindingData::DomainToASCII(const FunctionCallbackInfo<Value>& args) {

std::string input = Utf8Value(env->isolate(), args[0]).ToString();
if (input.empty()) {
return args.GetReturnValue().Set(FIXED_ONE_BYTE_STRING(env->isolate(), ""));
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}

// It is important to have an initial value that contains a special scheme.
Expand All @@ -87,7 +87,7 @@ void BindingData::DomainToASCII(const FunctionCallbackInfo<Value>& args) {
auto out = ada::parse<ada::url>("ws://x");
DCHECK(out);
if (!out->set_hostname(input)) {
return args.GetReturnValue().Set(FIXED_ONE_BYTE_STRING(env->isolate(), ""));
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}
std::string host = out->get_hostname();
args.GetReturnValue().Set(
Expand All @@ -101,8 +101,7 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo<Value>& args) {

std::string input = Utf8Value(env->isolate(), args[0]).ToString();
if (input.empty()) {
return args.GetReturnValue().Set(
String::NewFromUtf8(env->isolate(), "").ToLocalChecked());
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}

// It is important to have an initial value that contains a special scheme.
Expand All @@ -111,8 +110,7 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo<Value>& args) {
auto out = ada::parse<ada::url>("ws://x");
DCHECK(out);
if (!out->set_hostname(input)) {
return args.GetReturnValue().Set(
String::NewFromUtf8(env->isolate(), "").ToLocalChecked());
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}
std::string result = ada::unicode::to_unicode(out->get_hostname());

Expand Down

0 comments on commit a3ae7a5

Please sign in to comment.