Skip to content

Commit

Permalink
Cherry-pick a6c922e. rdar://problem/101518569
Browse files Browse the repository at this point in the history
    Punycode U+0E01 when in the context of non-Thai characters
    https://bugs.webkit.org/show_bug.cgi?id=247287
    rdar://101434628

    Reviewed by Tim Horton.

    * Source/WTF/wtf/URLHelpers.cpp:
    (WTF::URLHelpers::isLookalikeCharacterOfScriptType<USCRIPT_THAI>):
    (WTF::URLHelpers::isLookalikeCharacter):
    * Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm:
    (TestWebKitAPI::TEST):

    Canonical link: https://commits.webkit.org/256276@main

Canonical link: https://commits.webkit.org/245886.841@safari-7613.4.1.0-branch
  • Loading branch information
Alex Christensen authored and alancoon committed Nov 9, 2022
1 parent 44e845a commit 04050e1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions LayoutTests/fast/encoding/idn-security-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ PASS testIDNRoundTrip(0x30a1) is '%u30A1'
PASS testIDNRoundTripNotFirstCharacter(0x30a1) is '%u30A1'
PASS testIDNRoundTrip(0xb94) is '%u0B94'
PASS testIDNRoundTripNotFirstCharacter(0xb94) is '%u0B94'
PASS testIDNRoundTrip(0xe01) is '%u0E01'
PASS testIDNRoundTripNotFirstCharacter(0xe01) is '%u0E01'
PASS testIDNRoundTrip(0xe02) is '%u0E02'
PASS testIDNRoundTripNotFirstCharacter(0xe02) is '%u0E02'
PASS testIDNRoundTrip(0xa000) is '%uA000'
PASS testIDNRoundTripNotFirstCharacter(0xa000) is '%uA000'
PASS testIDNRoundTrip(0xff0f) is '/'
Expand Down
2 changes: 1 addition & 1 deletion LayoutTests/fast/encoding/idn-security.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
testIDNCharacter(0x3041, "allowed");
testIDNCharacter(0x30A1, "allowed");
testIDNCharacter(0x0B94, "allowed");
testIDNCharacter(0x0E01, "allowed");
testIDNCharacter(0x0E02, "allowed");
testIDNCharacter(0xA000, "allowed");

/* ICU converts these to other allowed characters, so the original character can't be used to get to a phishy domain name */
Expand Down
11 changes: 11 additions & 0 deletions Source/WTF/wtf/URLHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ template<> bool isLookalikeCharacterOfScriptType<USCRIPT_CANADIAN_ABORIGINAL>(UC
}
}

template<> bool isLookalikeCharacterOfScriptType<USCRIPT_THAI>(UChar32 codePoint)
{
switch (codePoint) {
case 0x0E01: // THAI CHARACTER KO KAI
return true;
default:
return false;
}
}

template <UScriptCode ScriptType>
bool isOfScriptType(UChar32 codePoint)
{
Expand Down Expand Up @@ -314,6 +324,7 @@ static bool isLookalikeCharacter(const std::optional<UChar32>& previousCodePoint
return isLookalikeSequence<USCRIPT_ARMENIAN>(previousCodePoint, codePoint)
|| isLookalikeSequence<USCRIPT_TAMIL>(previousCodePoint, codePoint)
|| isLookalikeSequence<USCRIPT_CANADIAN_ABORIGINAL>(previousCodePoint, codePoint)
|| isLookalikeSequence<USCRIPT_THAI>(previousCodePoint, codePoint)
|| isLookalikeSequence<USCRIPT_ARABIC>(previousCodePoint, codePoint);
}
}
Expand Down
5 changes: 5 additions & 0 deletions Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
"xn--o-10e", // 'o' U+0BE6
"xn--a-53i", // U+15AF 'a'
"xn--a-63i", // 'a' U+15AF
"xn--n-twf", // U+0E01 'n'
"xn--n-uwf", // 'n' U+0E01
"xn--3hb112n", // U+065B
"xn--a-ypc062v", // 'a' U+065B
};
Expand Down Expand Up @@ -163,6 +165,9 @@
// Canadian aboriginal
EXPECT_STREQ("https://\u15AF\u1401abc/", userVisibleString(literalURL("https://\u15AF\u1401abc/")));

// Thai
EXPECT_STREQ("https://\u0E01\u0E02abc/", userVisibleString(literalURL("https://\u0E01\u0E02abc/")));

// Arabic
EXPECT_STREQ("https://\u0620\u065Babc/", userVisibleString(literalURL("https://\u0620\u065Babc/")));
}
Expand Down

0 comments on commit 04050e1

Please sign in to comment.