src: remove explicit UTF-8 validity check in url

This step was never part of the URL Standard's host parser algorithm,
and is rendered unnecessary after IDNA errors are no longer ignored.

PR-URL: https://github.com/nodejs/node/pull/12507
Refs: c2a302c50b "src: do not ignore IDNA conversion error"
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Timothy Gu authored and Evan Lucas committed 2017-05-01 11:16:05 -05:00
1 parent b8ff2c9f37
commit 72a3cacc95
1 file changed
-30
-30
View File
@@ -15,11 +15,6 @@
#include <stdio.h>
#include <cmath>
#if defined(NODE_HAVE_I18N_SUPPORT)
#include <unicode/utf8.h>
#include <unicode/utf.h>
#endif
#define UNICODE_REPLACEMENT_CHARACTER 0xFFFD
namespace node {
@@ -74,21 +69,6 @@ namespace url {
output->assign(*buf, buf.length());
return true;
}
// Unfortunately there's not really a better way to do this.
// Iterate through each encoded codepoint and verify that
// it is a valid unicode codepoint.
static bool IsValidUTF8(std::string* input) {
const char* p = input->c_str();
int32_t len = input->length();
for (int32_t i = 0; i < len;) {
UChar32 c;
U8_NEXT_UNSAFE(p, i, c);
if (!U_IS_UNICODE_CHAR(c))
return false;
}
return true;
}
#else
// Intentional non-ops if ICU is not present.
static inline bool ToUnicode(std::string* input, std::string* output) {
@@ -100,10 +80,6 @@ namespace url {
*output = *input;
return true;
}
static bool IsValidUTF8(std::string* input) {
return true;
}
#endif
// If a UTF-16 character is a low/trailing surrogate.
@@ -355,12 +331,6 @@ namespace url {
// First, we have to percent decode
PercentDecode(input, length, &decoded);
// If there are any invalid UTF8 byte sequences, we have to fail.
// Unfortunately this means iterating through the string and checking
// each decoded codepoint.
if (!IsValidUTF8(&decoded))
goto end;
// Then we have to punycode toASCII
if (!ToASCII(&decoded, &decoded))
goto end;