Bug 1753954 - Normalize single number with trailing dot correctly, r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D138004
This commit is contained in:
Kershaw Chang 2022-02-07 14:50:24 +00:00
Родитель 2e614a08ce
Коммит 8dee9057db
2 изменённых файлов: 14 добавлений и 1 удалений

Просмотреть файл

@ -604,6 +604,12 @@ nsresult nsStandardURL::NormalizeIPv4(const nsACString& host,
ipv4 += number << (8 * (3 - i));
}
// A special case for ipv4 URL like "127." should have the same result as
// "127".
if (dotCount == 1 && dotIndex[0] == length - 1) {
ipv4 = (ipv4 & 0xff000000) >> 24;
}
uint8_t ipSegments[4];
NetworkEndian::writeUint32(ipSegments, ipv4);
result = nsPrintfCString("%d.%d.%d.%d", ipSegments[0], ipSegments[1],

Просмотреть файл

@ -241,11 +241,18 @@ TEST(TestStandardURL, From_test_standardurldotjs)
"1.2.3.4.5", "010000000000000000",
"2+3", "0.0.0.-1",
"1.2.3.4..", "1..2",
".1.2.3.4"};
".1.2.3.4", ".127"};
for (auto& nonIPv4 : nonIPv4s) {
nsCString encHost(nonIPv4);
ASSERT_EQ(NS_ERROR_FAILURE, Test_NormalizeIPv4(encHost, result));
}
const char* oneOrNoDotsIPv4s[] = {"127", "127."};
for (auto& localIPv4 : oneOrNoDotsIPv4s) {
nsCString encHost(localIPv4);
ASSERT_EQ(NS_OK, Test_NormalizeIPv4(encHost, result));
ASSERT_TRUE(result.EqualsLiteral("0.0.0.127"));
}
}
#define TEST_COUNT 10000