Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v18.x] backport: src: replace idna functions with ada::idna #48872

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/idna.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

const { domainToASCII, domainToUnicode } = require('internal/url');
module.exports = { toASCII: domainToASCII, toUnicode: domainToUnicode };
const { toASCII, toUnicode } = internalBinding('url');
module.exports = { toASCII, toUnicode };
26 changes: 26 additions & 0 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,28 @@ void BindingData::Update(const FunctionCallbackInfo<Value>& args) {
.ToLocalChecked());
}

void BindingData::ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_GE(args.Length(), 1);
CHECK(args[0]->IsString());

Utf8Value input(env->isolate(), args[0]);
auto out = ada::idna::to_ascii(input.ToStringView());
args.GetReturnValue().Set(
String::NewFromUtf8(env->isolate(), out.c_str()).ToLocalChecked());
}

void BindingData::ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_GE(args.Length(), 1);
CHECK(args[0]->IsString());

Utf8Value input(env->isolate(), args[0]);
auto out = ada::idna::to_unicode(input.ToStringView());
args.GetReturnValue().Set(
String::NewFromUtf8(env->isolate(), out.c_str()).ToLocalChecked());
}

void BindingData::UpdateComponents(const ada::url_components& components,
const ada::scheme::type type) {
url_components_buffer_[0] = components.protocol_end;
Expand All @@ -318,6 +340,8 @@ void BindingData::Initialize(Local<Object> target,
realm->AddBindingData<BindingData>(context, target);
if (binding_data == nullptr) return;

SetMethodNoSideEffect(context, target, "toASCII", ToASCII);
SetMethodNoSideEffect(context, target, "toUnicode", ToUnicode);
SetMethodNoSideEffect(context, target, "domainToASCII", DomainToASCII);
SetMethodNoSideEffect(context, target, "domainToUnicode", DomainToUnicode);
SetMethodNoSideEffect(context, target, "canParse", CanParse);
Expand All @@ -328,6 +352,8 @@ void BindingData::Initialize(Local<Object> target,

void BindingData::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(ToASCII);
registry->Register(ToUnicode);
registry->Register(DomainToASCII);
registry->Register(DomainToUnicode);
registry->Register(CanParse);
Expand Down
3 changes: 3 additions & 0 deletions src/node_url.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class BindingData : public SnapshotableObject {
SET_SELF_SIZE(BindingData)
SET_MEMORY_INFO_NAME(BindingData)

static void ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args);
static void ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args);

static void DomainToASCII(const v8::FunctionCallbackInfo<v8::Value>& args);
static void DomainToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args);

Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-url-parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';
require('../common');
const assert = require('assert');
const url = require('url');

assert.strictEqual(url.parse('x://0.0,1.1/').host, '0.0,1.1');