-
Notifications
You must be signed in to change notification settings - Fork 29.3k
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
src: do not ignore IDNA conversion error #11549
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
src: do not ignore IDNA conversion error
Old behavior can be restored using a special `lenient` mode.
- Loading branch information
commit a6fef08d551520c503a93e5fa714f041ee5eaa6a
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,7 +410,8 @@ bool InitializeICUDirectory(const std::string& path) { | |
|
||
int32_t ToUnicode(MaybeStackBuffer<char>* buf, | ||
const char* input, | ||
size_t length) { | ||
size_t length, | ||
bool lenient) { | ||
UErrorCode status = U_ZERO_ERROR; | ||
uint32_t options = UIDNA_DEFAULT; | ||
options |= UIDNA_NONTRANSITIONAL_TO_UNICODE; | ||
|
@@ -435,7 +436,7 @@ int32_t ToUnicode(MaybeStackBuffer<char>* buf, | |
&status); | ||
} | ||
|
||
if (U_FAILURE(status)) { | ||
if (U_FAILURE(status) || (!lenient && info.errors != 0)) { | ||
len = -1; | ||
buf->SetLength(0); | ||
} else { | ||
|
@@ -448,7 +449,8 @@ int32_t ToUnicode(MaybeStackBuffer<char>* buf, | |
|
||
int32_t ToASCII(MaybeStackBuffer<char>* buf, | ||
const char* input, | ||
size_t length) { | ||
size_t length, | ||
bool lenient) { | ||
UErrorCode status = U_ZERO_ERROR; | ||
uint32_t options = UIDNA_DEFAULT; | ||
options |= UIDNA_NONTRANSITIONAL_TO_ASCII; | ||
|
@@ -473,7 +475,7 @@ int32_t ToASCII(MaybeStackBuffer<char>* buf, | |
&status); | ||
} | ||
|
||
if (U_FAILURE(status)) { | ||
if (U_FAILURE(status) || (!lenient && info.errors != 0)) { | ||
len = -1; | ||
buf->SetLength(0); | ||
} else { | ||
|
@@ -489,8 +491,11 @@ static void ToUnicode(const FunctionCallbackInfo<Value>& args) { | |
CHECK_GE(args.Length(), 1); | ||
CHECK(args[0]->IsString()); | ||
Utf8Value val(env->isolate(), args[0]); | ||
// optional arg | ||
bool lenient = args[1]->BooleanValue(env->context()).FromJust(); | ||
|
||
MaybeStackBuffer<char> buf; | ||
int32_t len = ToUnicode(&buf, *val, val.length()); | ||
int32_t len = ToUnicode(&buf, *val, val.length(), lenient); | ||
|
||
if (len < 0) { | ||
return env->ThrowError("Cannot convert name to Unicode"); | ||
|
@@ -508,8 +513,11 @@ static void ToASCII(const FunctionCallbackInfo<Value>& args) { | |
CHECK_GE(args.Length(), 1); | ||
CHECK(args[0]->IsString()); | ||
Utf8Value val(env->isolate(), args[0]); | ||
// optional arg | ||
bool lenient = args[1]->BooleanValue(env->context()).FromJust(); | ||
|
||
MaybeStackBuffer<char> buf; | ||
int32_t len = ToASCII(&buf, *val, val.length()); | ||
int32_t len = ToASCII(&buf, *val, val.length(), lenient); | ||
|
||
if (len < 0) { | ||
return env->ThrowError("Cannot convert name to ASCII"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this error part of any non-experimental API? Could we change it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes for > url.parse(`http://${'é'.repeat(230)}.com/`)
Error: Cannot convert name to ASCII |
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this error part of any non-experimental API? Could we change it to
Cannot decode name as Punycode
? (basically the same question I also posted below).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No; in fact the
toUnicode
JS function isn't used in the code base at all. Maybe we should just remove this method?/cc @jasnell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not used, it can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove which function specifically? The `i18n::ToUnicode' function is definitely used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell, the exposed
process.binding('icu').toUnicode()
JS function.