1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
|
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2010-2014, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* file name: uts46test.cpp
* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
* created on: 2010may05
* created by: Markus W. Scherer
*/
#include "unicode/utypes.h"
#if !UCONFIG_NO_IDNA
#include <string.h>
#include "unicode/bytestream.h"
#include "unicode/idna.h"
#include "unicode/localpointer.h"
#include "unicode/std_string.h"
#include "unicode/stringpiece.h"
#include "unicode/uidna.h"
#include "unicode/unistr.h"
#include "charstr.h"
#include "cmemory.h"
#include "intltest.h"
#include "punycode.h"
#include "uparse.h"
class UTS46Test : public IntlTest {
public:
UTS46Test() : trans(nullptr), nontrans(nullptr) {}
virtual ~UTS46Test();
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=nullptr) override;
void TestAPI();
void TestNotSTD3();
void TestInvalidPunycodeDigits();
void TestACELabelEdgeCases();
void TestDefaultNontransitional();
void TestTooLong();
void TestSomeCases();
void IdnaTest();
void checkIdnaTestResult(const char *line, const char *type,
const UnicodeString &expected, const UnicodeString &result,
const char *status, const IDNAInfo &info);
void idnaTestOneLine(char *fields[][2], UErrorCode &errorCode);
private:
IDNA *trans, *nontrans;
};
extern IntlTest *createUTS46Test() {
return new UTS46Test();
}
UTS46Test::~UTS46Test() {
delete trans;
delete nontrans;
}
void UTS46Test::runIndexedTest(int32_t index, UBool exec, const char *&name, char * /*par*/) {
if(exec) {
logln("TestSuite UTS46Test: ");
if(trans==nullptr) {
IcuTestErrorCode errorCode(*this, "init/createUTS46Instance()");
uint32_t commonOptions=
UIDNA_USE_STD3_RULES|UIDNA_CHECK_BIDI|
UIDNA_CHECK_CONTEXTJ|UIDNA_CHECK_CONTEXTO;
trans=IDNA::createUTS46Instance(commonOptions, errorCode);
nontrans=IDNA::createUTS46Instance(
commonOptions|
UIDNA_NONTRANSITIONAL_TO_ASCII|UIDNA_NONTRANSITIONAL_TO_UNICODE,
errorCode);
if(errorCode.errDataIfFailureAndReset("createUTS46Instance()")) {
name="";
return;
}
}
}
TESTCASE_AUTO_BEGIN;
TESTCASE_AUTO(TestAPI);
TESTCASE_AUTO(TestNotSTD3);
TESTCASE_AUTO(TestInvalidPunycodeDigits);
TESTCASE_AUTO(TestACELabelEdgeCases);
TESTCASE_AUTO(TestDefaultNontransitional);
TESTCASE_AUTO(TestTooLong);
TESTCASE_AUTO(TestSomeCases);
TESTCASE_AUTO(IdnaTest);
TESTCASE_AUTO_END;
}
namespace {
const uint32_t severeErrors=
UIDNA_ERROR_LEADING_COMBINING_MARK|
UIDNA_ERROR_DISALLOWED|
UIDNA_ERROR_PUNYCODE|
UIDNA_ERROR_LABEL_HAS_DOT|
UIDNA_ERROR_INVALID_ACE_LABEL;
UBool isASCII(const UnicodeString &str) {
const char16_t *s=str.getBuffer();
int32_t length=str.length();
for(int32_t i=0; i<length; ++i) {
if(s[i]>=0x80) {
return false;
}
}
return true;
}
class TestCheckedArrayByteSink : public CheckedArrayByteSink {
public:
TestCheckedArrayByteSink(char* outbuf, int32_t capacity)
: CheckedArrayByteSink(outbuf, capacity), calledFlush(false) {}
virtual CheckedArrayByteSink& Reset() override {
CheckedArrayByteSink::Reset();
calledFlush = false;
return *this;
}
virtual void Flush() override { calledFlush = true; }
UBool calledFlush;
};
} // namespace
void UTS46Test::TestAPI() {
UErrorCode errorCode=U_ZERO_ERROR;
UnicodeString result;
IDNAInfo info;
UnicodeString input=UNICODE_STRING_SIMPLE("www.eXample.cOm");
UnicodeString expected=UNICODE_STRING_SIMPLE("www.example.com");
trans->nameToASCII(input, result, info, errorCode);
if(U_FAILURE(errorCode) || info.hasErrors() || result!=expected) {
errln("T.nameToASCII(www.example.com) info.errors=%04lx result matches=%d %s",
static_cast<long>(info.getErrors()), result == expected, u_errorName(errorCode));
}
errorCode=U_USELESS_COLLATOR_ERROR;
trans->nameToUnicode(input, result, info, errorCode);
if(errorCode!=U_USELESS_COLLATOR_ERROR || !result.isBogus()) {
errln("T.nameToUnicode(U_FAILURE) did not preserve the errorCode "
"or not result.setToBogus() - %s",
u_errorName(errorCode));
}
errorCode=U_ZERO_ERROR;
input.setToBogus();
result=UNICODE_STRING_SIMPLE("quatsch");
nontrans->labelToASCII(input, result, info, errorCode);
if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || !result.isBogus()) {
errln("N.labelToASCII(bogus) did not set illegal-argument-error "
"or not result.setToBogus() - %s",
u_errorName(errorCode));
}
errorCode=U_ZERO_ERROR;
input=UNICODE_STRING_SIMPLE("xn--bcher.de-65a");
expected=UNICODE_STRING_SIMPLE("xn--bcher\\uFFFDde-65a").unescape();
nontrans->labelToASCII(input, result, info, errorCode);
if( U_FAILURE(errorCode) ||
info.getErrors()!=(UIDNA_ERROR_LABEL_HAS_DOT|UIDNA_ERROR_INVALID_ACE_LABEL) ||
result!=expected
) {
errln("N.labelToASCII(label-with-dot) failed with errors %04lx - %s",
info.getErrors(), u_errorName(errorCode));
}
// UTF-8
char buffer[100];
TestCheckedArrayByteSink sink(buffer, UPRV_LENGTHOF(buffer));
errorCode=U_ZERO_ERROR;
nontrans->labelToUnicodeUTF8(StringPiece((const char *)nullptr, 5), sink, info, errorCode);
if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || sink.NumberOfBytesWritten()!=0) {
errln("N.labelToUnicodeUTF8(StringPiece(nullptr, 5)) did not set illegal-argument-error ",
"or did output something - %s",
u_errorName(errorCode));
}
sink.Reset();
errorCode=U_ZERO_ERROR;
nontrans->nameToASCII_UTF8(StringPiece(), sink, info, errorCode);
if(U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=0 || !sink.calledFlush) {
errln("N.nameToASCII_UTF8(empty) failed - %s",
u_errorName(errorCode));
}
static const char s[] = { 0x61, static_cast<char>(0xc3), static_cast<char>(0x9f) };
sink.Reset();
errorCode=U_USELESS_COLLATOR_ERROR;
nontrans->nameToUnicodeUTF8(StringPiece(s, 3), sink, info, errorCode);
if(errorCode!=U_USELESS_COLLATOR_ERROR || sink.NumberOfBytesWritten()!=0) {
errln("N.nameToUnicode_UTF8(U_FAILURE) did not preserve the errorCode "
"or did output something - %s",
u_errorName(errorCode));
}
sink.Reset();
errorCode=U_ZERO_ERROR;
trans->labelToUnicodeUTF8(StringPiece(s, 3), sink, info, errorCode);
if( U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=3 ||
buffer[0]!=0x61 || buffer[1]!=0x73 || buffer[2]!=0x73 ||
!sink.calledFlush
) {
errln("T.labelToUnicodeUTF8(a sharp-s) failed - %s",
u_errorName(errorCode));
}
sink.Reset();
errorCode=U_ZERO_ERROR;
// "eXampLe.cOm"
static const char eX[]={ 0x65, 0x58, 0x61, 0x6d, 0x70, 0x4c, 0x65, 0x2e, 0x63, 0x4f, 0x6d, 0 };
// "example.com"
static const char ex[]={ 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d };
trans->nameToUnicodeUTF8(eX, sink, info, errorCode);
if( U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=11 ||
0!=memcmp(ex, buffer, 11) || !sink.calledFlush
) {
errln("T.nameToUnicodeUTF8(eXampLe.cOm) failed - %s",
u_errorName(errorCode));
}
}
void UTS46Test::TestNotSTD3() {
IcuTestErrorCode errorCode(*this, "TestNotSTD3()");
char buffer[400];
LocalPointer<IDNA> not3(IDNA::createUTS46Instance(UIDNA_CHECK_BIDI, errorCode));
if(errorCode.isFailure()) {
return;
}
UnicodeString input=UNICODE_STRING_SIMPLE("\\u0000A_2+2=4\\u000A.e\\u00DFen.net").unescape();
UnicodeString result;
IDNAInfo info;
if( not3->nameToUnicode(input, result, info, errorCode)!=
UNICODE_STRING_SIMPLE("\\u0000a_2+2=4\\u000A.essen.net").unescape() ||
info.hasErrors()
) {
prettify(result).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
errln("notSTD3.nameToUnicode(non-LDH ASCII) unexpected errors %04lx string %s",
static_cast<long>(info.getErrors()), buffer);
}
// A space (BiDi class WS) is not allowed in a BiDi domain name.
input=UNICODE_STRING_SIMPLE("a z.xn--4db.edu");
not3->nameToASCII(input, result, info, errorCode);
if(result!=input || info.getErrors()!=UIDNA_ERROR_BIDI) {
errln("notSTD3.nameToASCII(ASCII-with-space.alef.edu) failed");
}
}
void UTS46Test::TestInvalidPunycodeDigits() {
IcuTestErrorCode errorCode(*this, "TestInvalidPunycodeDigits()");
LocalPointer<IDNA> idna(IDNA::createUTS46Instance(0, errorCode));
if(errorCode.isFailure()) {
return;
}
UnicodeString result;
{
IDNAInfo info;
idna->nameToUnicode(u"xn--pleP", result, info, errorCode); // P=U+0050
assertFalse("nameToUnicode() should succeed",
(info.getErrors()&UIDNA_ERROR_PUNYCODE)!=0);
assertEquals("normal result", u"ᔼᔴ", result);
}
{
IDNAInfo info;
idna->nameToUnicode(u"xn--pleѐ", result, info, errorCode); // ends with non-ASCII U+0450
assertTrue("nameToUnicode() should detect non-ASCII",
(info.getErrors()&UIDNA_ERROR_PUNYCODE)!=0);
}
// Test with ASCII characters adjacent to LDH.
{
IDNAInfo info;
idna->nameToUnicode(u"xn--ple/", result, info, errorCode);
assertTrue("nameToUnicode() should detect '/'",
(info.getErrors()&UIDNA_ERROR_PUNYCODE)!=0);
}
{
IDNAInfo info;
idna->nameToUnicode(u"xn--ple:", result, info, errorCode);
assertTrue("nameToUnicode() should detect ':'",
(info.getErrors()&UIDNA_ERROR_PUNYCODE)!=0);
}
{
IDNAInfo info;
idna->nameToUnicode(u"xn--ple@", result, info, errorCode);
assertTrue("nameToUnicode() should detect '@'",
(info.getErrors()&UIDNA_ERROR_PUNYCODE)!=0);
}
{
IDNAInfo info;
idna->nameToUnicode(u"xn--ple[", result, info, errorCode);
assertTrue("nameToUnicode() should detect '['",
(info.getErrors()&UIDNA_ERROR_PUNYCODE)!=0);
}
{
IDNAInfo info;
idna->nameToUnicode(u"xn--ple`", result, info, errorCode);
assertTrue("nameToUnicode() should detect '`'",
(info.getErrors()&UIDNA_ERROR_PUNYCODE)!=0);
}
{
IDNAInfo info;
idna->nameToUnicode(u"xn--ple{", result, info, errorCode);
assertTrue("nameToUnicode() should detect '{'",
(info.getErrors()&UIDNA_ERROR_PUNYCODE)!=0);
}
}
void UTS46Test::TestACELabelEdgeCases() {
// In IDNA2008, these labels fail the round-trip validation from comparing
// the ToUnicode input with the back-to-ToASCII output.
IcuTestErrorCode errorCode(*this, "TestACELabelEdgeCases()");
LocalPointer<IDNA> idna(IDNA::createUTS46Instance(0, errorCode));
if(errorCode.isFailure()) {
return;
}
UnicodeString result;
{
IDNAInfo info;
idna->labelToUnicode(u"xn--", result, info, errorCode);
assertTrue("empty xn--", (info.getErrors()&UIDNA_ERROR_INVALID_ACE_LABEL)!=0);
}
{
IDNAInfo info;
idna->labelToUnicode(u"xN--ASCII-", result, info, errorCode);
assertTrue("nothing but ASCII", (info.getErrors()&UIDNA_ERROR_INVALID_ACE_LABEL)!=0);
}
{
// Different error: The Punycode decoding procedure does not consume the last delimiter
// if it is right after the xn-- so the main decoding loop fails because the hyphen
// is not a valid Punycode digit.
IDNAInfo info;
idna->labelToUnicode(u"Xn---", result, info, errorCode);
assertTrue("empty Xn---", (info.getErrors()&UIDNA_ERROR_PUNYCODE)!=0);
}
{
// Unicode 15.1 UTS #46:
// Added an additional condition in 4.1 Validity Criteria to
// disallow labels such as xn--xn---epa., which do not round-trip.
// --> Validity Criteria new criterion 4:
// If not CheckHyphens, the label must not begin with “xn--”.
IDNAInfo info;
idna->labelToUnicode("xn--xn---epa", result, info, errorCode);
assertTrue("error for xn--xn---epa",
(info.getErrors()&UIDNA_ERROR_INVALID_ACE_LABEL)!=0);
}
}
void UTS46Test::TestDefaultNontransitional() {
IcuTestErrorCode errorCode(*this, "TestDefaultNontransitional()");
// Unicode 15.1 UTS #46 deprecated transitional processing.
// ICU 76 changed UIDNA_DEFAULT to set the nontransitional options.
LocalPointer<IDNA> forZero(IDNA::createUTS46Instance(0, errorCode));
LocalPointer<IDNA> forDefault(IDNA::createUTS46Instance(UIDNA_DEFAULT, errorCode));
if(errorCode.isFailure()) {
return;
}
UnicodeString result;
IDNAInfo info;
forZero->labelToUnicode(u"Fⓤßẞ", result, info, errorCode);
assertEquals("forZero.toUnicode(Fⓤßẞ)", u"fussss", result);
forZero->labelToASCII(u"Fⓤßẞ", result, info, errorCode);
assertEquals("forZero.toASCII(Fⓤßẞ)", u"fussss", result);
forDefault->labelToUnicode(u"Fⓤßẞ", result, info, errorCode);
assertEquals("forDefault.toUnicode(Fⓤßẞ)", u"fußß", result);
forDefault->labelToASCII(u"Fⓤßẞ", result, info, errorCode);
assertEquals("forDefault.toASCII(Fⓤßẞ)", u"xn--fu-hiaa", result);
}
void UTS46Test::TestTooLong() {
// ICU-13727: Limit input length for n^2 algorithm
// where well-formed strings are at most 59 characters long.
int32_t count = 50000;
UnicodeString s(count, u'a', count); // capacity, code point, count
char16_t dest[60000];
UErrorCode errorCode = U_ZERO_ERROR;
u_strToPunycode(s.getBuffer(), s.length(), dest, UPRV_LENGTHOF(dest), nullptr, &errorCode);
assertEquals("encode: expected an error for too-long input", U_INPUT_TOO_LONG_ERROR, errorCode);
errorCode = U_ZERO_ERROR;
u_strFromPunycode(s.getBuffer(), s.length(), dest, UPRV_LENGTHOF(dest), nullptr, &errorCode);
assertEquals("decode: expected an error for too-long input", U_INPUT_TOO_LONG_ERROR, errorCode);
}
namespace {
struct TestCase {
// Input string and options string (Nontransitional/Transitional/Both).
const char *s, *o;
// Expected Unicode result string.
const char *u;
uint32_t errors;
};
const TestCase testCases[] = {
{ "www.eXample.cOm", "B", // all ASCII
"www.example.com", 0 },
{ "B\\u00FCcher.de", "B", // u-umlaut
"b\\u00FCcher.de", 0 },
{ "\\u00D6BB", "B", // O-umlaut
"\\u00F6bb", 0 },
{ "fa\\u00DF.de", "N", // sharp s
"fa\\u00DF.de", 0 },
{ "fa\\u00DF.de", "T", // sharp s
"fass.de", 0 },
{ "XN--fA-hia.dE", "B", // sharp s in Punycode
"fa\\u00DF.de", 0 },
{ "\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2.com", "N", // Greek with final sigma
"\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2.com", 0 },
{ "\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2.com", "T", // Greek with final sigma
"\\u03B2\\u03CC\\u03BB\\u03BF\\u03C3.com", 0 },
{ "xn--nxasmm1c", "B", // Greek with final sigma in Punycode
"\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2", 0 },
{ "www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", "N", // "Sri" in "Sri Lanka" has a ZWJ
"www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", 0 },
{ "www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", "T", // "Sri" in "Sri Lanka" has a ZWJ
"www.\\u0DC1\\u0DCA\\u0DBB\\u0DD3.com", 0 },
{ "www.xn--10cl1a0b660p.com", "B", // "Sri" in Punycode
"www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", 0 },
{ "\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC", "N", // ZWNJ
"\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC", 0 },
{ "\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC", "T", // ZWNJ
"\\u0646\\u0627\\u0645\\u0647\\u0627\\u06CC", 0 },
{ "xn--mgba3gch31f060k.com", "B", // ZWNJ in Punycode
"\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC.com", 0 },
{ "a.b\\uFF0Ec\\u3002d\\uFF61", "B",
"a.b.c.d.", 0 },
{ "U\\u0308.xn--tda", "B", // U+umlaut.u-umlaut
"\\u00FC.\\u00FC", 0 },
{ "xn--u-ccb", "B", // u+umlaut in Punycode
"xn--u-ccb\\uFFFD", UIDNA_ERROR_INVALID_ACE_LABEL },
{ "a\\u2488com", "B", // contains 1-dot
"a\\uFFFDcom", UIDNA_ERROR_DISALLOWED },
{ "xn--a-ecp.ru", "B", // contains 1-dot in Punycode
"xn--a-ecp\\uFFFD.ru", UIDNA_ERROR_INVALID_ACE_LABEL },
{ "xn--0.pt", "B", // invalid Punycode
"xn--0\\uFFFD.pt", UIDNA_ERROR_PUNYCODE },
{ "xn--a.pt", "B", // U+0080
"xn--a\\uFFFD.pt", UIDNA_ERROR_INVALID_ACE_LABEL },
{ "xn--a-\\u00C4.pt", "B", // invalid Punycode
"xn--a-\\u00E4.pt", UIDNA_ERROR_PUNYCODE },
{ "\\u65E5\\u672C\\u8A9E\\u3002\\uFF2A\\uFF30", "B", // Japanese with fullwidth ".jp"
"\\u65E5\\u672C\\u8A9E.jp", 0 },
{ "\\u2615", "B", "\\u2615", 0 }, // Unicode 4.0 HOT BEVERAGE
// many deviation characters, test the special mapping code
{ "1.a\\u00DF\\u200C\\u200Db\\u200C\\u200Dc\\u00DF\\u00DF\\u00DF\\u00DFd"
"\\u03C2\\u03C3\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFe"
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFx"
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFy"
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u0302\\u00DFz", "N",
"1.a\\u00DF\\u200C\\u200Db\\u200C\\u200Dc\\u00DF\\u00DF\\u00DF\\u00DFd"
"\\u03C2\\u03C3\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFe"
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFx"
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFy"
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u0302\\u00DFz",
UIDNA_ERROR_LABEL_TOO_LONG|UIDNA_ERROR_CONTEXTJ },
{ "1.a\\u00DF\\u200C\\u200Db\\u200C\\u200Dc\\u00DF\\u00DF\\u00DF\\u00DFd"
"\\u03C2\\u03C3\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFe"
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFx"
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFy"
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u0302\\u00DFz", "T",
"1.assbcssssssssd"
"\\u03C3\\u03C3sssssssssssssssse"
"ssssssssssssssssssssx"
"ssssssssssssssssssssy"
"sssssssssssssss\\u015Dssz", UIDNA_ERROR_LABEL_TOO_LONG },
// "xn--bss" with deviation characters
{ "\\u200Cx\\u200Dn\\u200C-\\u200D-b\\u00DF", "N",
"\\u200Cx\\u200Dn\\u200C-\\u200D-b\\u00DF", UIDNA_ERROR_CONTEXTJ },
{ "\\u200Cx\\u200Dn\\u200C-\\u200D-b\\u00DF", "T",
"\\u5919", 0 },
// "xn--bssffl" written as:
// 02E3 MODIFIER LETTER SMALL X
// 034F COMBINING GRAPHEME JOINER (ignored)
// 2115 DOUBLE-STRUCK CAPITAL N
// 200B ZERO WIDTH SPACE (ignored)
// FE63 SMALL HYPHEN-MINUS
// 00AD SOFT HYPHEN (ignored)
// FF0D FULLWIDTH HYPHEN-MINUS
// 180C MONGOLIAN FREE VARIATION SELECTOR TWO (ignored)
// 212C SCRIPT CAPITAL B
// FE00 VARIATION SELECTOR-1 (ignored)
// 017F LATIN SMALL LETTER LONG S
// 2064 INVISIBLE PLUS (ignored)
// 1D530 MATHEMATICAL FRAKTUR SMALL S
// E01EF VARIATION SELECTOR-256 (ignored)
// FB04 LATIN SMALL LIGATURE FFL
{ "\\u02E3\\u034F\\u2115\\u200B\\uFE63\\u00AD\\uFF0D\\u180C"
"\\u212C\\uFE00\\u017F\\u2064\\U0001D530\\U000E01EF\\uFB04", "B",
"\\u5921\\u591E\\u591C\\u5919", 0 },
{ "123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901", 0 },
{ "123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901.", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901.", 0 },
// Domain name >256 characters, forces slow path in UTF-8 processing.
{ "123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"12345678901234567890123456789012345678901234567890123456789012", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"12345678901234567890123456789012345678901234567890123456789012",
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG },
{ "123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789\\u05D0", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789\\u05D0",
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG|UIDNA_ERROR_BIDI },
{ "123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901234."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901234."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890",
UIDNA_ERROR_LABEL_TOO_LONG },
{ "123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901234."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890.", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901234."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890.",
UIDNA_ERROR_LABEL_TOO_LONG },
{ "123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901234."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901234."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901",
UIDNA_ERROR_LABEL_TOO_LONG|UIDNA_ERROR_DOMAIN_NAME_TOO_LONG },
// label length 63: xn--1234567890123456789012345678901234567890123456789012345-9te
{ "\\u00E41234567890123456789012345678901234567890123456789012345", "B",
"\\u00E41234567890123456789012345678901234567890123456789012345", 0 },
{ "1234567890\\u00E41234567890123456789012345678901234567890123456", "B",
"1234567890\\u00E41234567890123456789012345678901234567890123456", UIDNA_ERROR_LABEL_TOO_LONG },
{ "123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E4123456789012345678901234567890123456789012345."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E4123456789012345678901234567890123456789012345."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901", 0 },
{ "123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E4123456789012345678901234567890123456789012345."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901.", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E4123456789012345678901234567890123456789012345."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901.", 0 },
{ "123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E4123456789012345678901234567890123456789012345."
"123456789012345678901234567890123456789012345678901234567890123."
"12345678901234567890123456789012345678901234567890123456789012", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E4123456789012345678901234567890123456789012345."
"123456789012345678901234567890123456789012345678901234567890123."
"12345678901234567890123456789012345678901234567890123456789012",
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG },
{ "123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E41234567890123456789012345678901234567890123456."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E41234567890123456789012345678901234567890123456."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890",
UIDNA_ERROR_LABEL_TOO_LONG },
{ "123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E41234567890123456789012345678901234567890123456."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890.", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E41234567890123456789012345678901234567890123456."
"123456789012345678901234567890123456789012345678901234567890123."
"123456789012345678901234567890123456789012345678901234567890.",
UIDNA_ERROR_LABEL_TOO_LONG },
{ "123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E41234567890123456789012345678901234567890123456."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901", "B",
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890\\u00E41234567890123456789012345678901234567890123456."
"123456789012345678901234567890123456789012345678901234567890123."
"1234567890123456789012345678901234567890123456789012345678901",
UIDNA_ERROR_LABEL_TOO_LONG|UIDNA_ERROR_DOMAIN_NAME_TOO_LONG },
// hyphen errors and empty-label errors
// Ticket #10883: ToUnicode also checks for empty labels.
{ ".", "B", ".", UIDNA_ERROR_EMPTY_LABEL },
{ "\\uFF0E", "B", ".", UIDNA_ERROR_EMPTY_LABEL },
// "xn---q----jra"=="-q--a-umlaut-"
{ "a.b..-q--a-.e", "B", "a.b..-q--a-.e",
UIDNA_ERROR_EMPTY_LABEL|UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN|
UIDNA_ERROR_HYPHEN_3_4 },
{ "a.b..-q--\\u00E4-.e", "B", "a.b..-q--\\u00E4-.e",
UIDNA_ERROR_EMPTY_LABEL|UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN|
UIDNA_ERROR_HYPHEN_3_4 },
{ "a.b..xn---q----jra.e", "B", "a.b..-q--\\u00E4-.e",
UIDNA_ERROR_EMPTY_LABEL|UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN|
UIDNA_ERROR_HYPHEN_3_4 },
{ "a..c", "B", "a..c", UIDNA_ERROR_EMPTY_LABEL },
{ "a.xn--.c", "B", "a.xn--\\uFFFD.c", UIDNA_ERROR_INVALID_ACE_LABEL },
{ "a.-b.", "B", "a.-b.", UIDNA_ERROR_LEADING_HYPHEN },
{ "a.b-.c", "B", "a.b-.c", UIDNA_ERROR_TRAILING_HYPHEN },
{ "a.-.c", "B", "a.-.c", UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN },
{ "a.bc--de.f", "B", "a.bc--de.f", UIDNA_ERROR_HYPHEN_3_4 },
{ "\\u00E4.\\u00AD.c", "B", "\\u00E4..c", UIDNA_ERROR_EMPTY_LABEL },
{ "\\u00E4.xn--.c", "B", "\\u00E4.xn--\\uFFFD.c", UIDNA_ERROR_INVALID_ACE_LABEL },
{ "\\u00E4.-b.", "B", "\\u00E4.-b.", UIDNA_ERROR_LEADING_HYPHEN },
{ "\\u00E4.b-.c", "B", "\\u00E4.b-.c", UIDNA_ERROR_TRAILING_HYPHEN },
{ "\\u00E4.-.c", "B", "\\u00E4.-.c", UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN },
{ "\\u00E4.bc--de.f", "B", "\\u00E4.bc--de.f", UIDNA_ERROR_HYPHEN_3_4 },
{ "a.b.\\u0308c.d", "B", "a.b.\\uFFFDc.d", UIDNA_ERROR_LEADING_COMBINING_MARK },
{ "a.b.xn--c-bcb.d", "B",
"a.b.xn--c-bcb\\uFFFD.d", UIDNA_ERROR_LEADING_COMBINING_MARK|UIDNA_ERROR_INVALID_ACE_LABEL },
// BiDi
{ "A0", "B", "a0", 0 },
{ "0A", "B", "0a", 0 }, // all-LTR is ok to start with a digit (EN)
{ "0A.\\u05D0", "B", // ASCII label does not start with L/R/AL
"0a.\\u05D0", UIDNA_ERROR_BIDI },
{ "c.xn--0-eha.xn--4db", "B", // 2nd label does not start with L/R/AL
"c.0\\u00FC.\\u05D0", UIDNA_ERROR_BIDI },
{ "b-.\\u05D0", "B", // label does not end with L/EN
"b-.\\u05D0", UIDNA_ERROR_TRAILING_HYPHEN|UIDNA_ERROR_BIDI },
{ "d.xn----dha.xn--4db", "B", // 2nd label does not end with L/EN
"d.\\u00FC-.\\u05D0", UIDNA_ERROR_TRAILING_HYPHEN|UIDNA_ERROR_BIDI },
{ "a\\u05D0", "B", "a\\u05D0", UIDNA_ERROR_BIDI }, // first dir != last dir
{ "\\u05D0\\u05C7", "B", "\\u05D0\\u05C7", 0 },
{ "\\u05D09\\u05C7", "B", "\\u05D09\\u05C7", 0 },
{ "\\u05D0a\\u05C7", "B", "\\u05D0a\\u05C7", UIDNA_ERROR_BIDI }, // first dir != last dir
{ "\\u05D0\\u05EA", "B", "\\u05D0\\u05EA", 0 },
{ "\\u05D0\\u05F3\\u05EA", "B", "\\u05D0\\u05F3\\u05EA", 0 },
{ "a\\u05D0Tz", "B", "a\\u05D0tz", UIDNA_ERROR_BIDI }, // mixed dir
{ "\\u05D0T\\u05EA", "B", "\\u05D0t\\u05EA", UIDNA_ERROR_BIDI }, // mixed dir
{ "\\u05D07\\u05EA", "B", "\\u05D07\\u05EA", 0 },
{ "\\u05D0\\u0667\\u05EA", "B", "\\u05D0\\u0667\\u05EA", 0 }, // Arabic 7 in the middle
{ "a7\\u0667z", "B", "a7\\u0667z", UIDNA_ERROR_BIDI }, // AN digit in LTR
{ "a7\\u0667", "B", "a7\\u0667", UIDNA_ERROR_BIDI }, // AN digit in LTR
{ "\\u05D07\\u0667\\u05EA", "B", // mixed EN/AN digits in RTL
"\\u05D07\\u0667\\u05EA", UIDNA_ERROR_BIDI },
{ "\\u05D07\\u0667", "B", // mixed EN/AN digits in RTL
"\\u05D07\\u0667", UIDNA_ERROR_BIDI },
// ZWJ
{ "\\u0BB9\\u0BCD\\u200D", "N", "\\u0BB9\\u0BCD\\u200D", 0 }, // Virama+ZWJ
{ "\\u0BB9\\u200D", "N", "\\u0BB9\\u200D", UIDNA_ERROR_CONTEXTJ }, // no Virama
{ "\\u200D", "N", "\\u200D", UIDNA_ERROR_CONTEXTJ }, // no Virama
// ZWNJ
{ "\\u0BB9\\u0BCD\\u200C", "N", "\\u0BB9\\u0BCD\\u200C", 0 }, // Virama+ZWNJ
{ "\\u0BB9\\u200C", "N", "\\u0BB9\\u200C", UIDNA_ERROR_CONTEXTJ }, // no Virama
{ "\\u200C", "N", "\\u200C", UIDNA_ERROR_CONTEXTJ }, // no Virama
{ "\\u0644\\u0670\\u200C\\u06ED\\u06EF", "N", // Joining types D T ZWNJ T R
"\\u0644\\u0670\\u200C\\u06ED\\u06EF", 0 },
{ "\\u0644\\u0670\\u200C\\u06EF", "N", // D T ZWNJ R
"\\u0644\\u0670\\u200C\\u06EF", 0 },
{ "\\u0644\\u200C\\u06ED\\u06EF", "N", // D ZWNJ T R
"\\u0644\\u200C\\u06ED\\u06EF", 0 },
{ "\\u0644\\u200C\\u06EF", "N", // D ZWNJ R
"\\u0644\\u200C\\u06EF", 0 },
{ "\\u0644\\u0670\\u200C\\u06ED", "N", // D T ZWNJ T
"\\u0644\\u0670\\u200C\\u06ED", UIDNA_ERROR_BIDI|UIDNA_ERROR_CONTEXTJ },
{ "\\u06EF\\u200C\\u06EF", "N", // R ZWNJ R
"\\u06EF\\u200C\\u06EF", UIDNA_ERROR_CONTEXTJ },
{ "\\u0644\\u200C", "N", // D ZWNJ
"\\u0644\\u200C", UIDNA_ERROR_BIDI|UIDNA_ERROR_CONTEXTJ },
{ "\\u0660\\u0661", "B", // Arabic-Indic Digits alone
"\\u0660\\u0661", UIDNA_ERROR_BIDI },
{ "\\u06F0\\u06F1", "B", // Extended Arabic-Indic Digits alone
"\\u06F0\\u06F1", 0 },
{ "\\u0660\\u06F1", "B", // Mixed Arabic-Indic Digits
"\\u0660\\u06F1", UIDNA_ERROR_CONTEXTO_DIGITS|UIDNA_ERROR_BIDI },
// All of the CONTEXTO "Would otherwise have been DISALLOWED" characters
// in their correct contexts,
// then each in incorrect context.
{ "l\\u00B7l\\u4E00\\u0375\\u03B1\\u05D0\\u05F3\\u05F4\\u30FB", "B",
"l\\u00B7l\\u4E00\\u0375\\u03B1\\u05D0\\u05F3\\u05F4\\u30FB", UIDNA_ERROR_BIDI },
{ "l\\u00B7", "B",
"l\\u00B7", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
{ "\\u00B7l", "B",
"\\u00B7l", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
{ "\\u0375", "B",
"\\u0375", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
{ "\\u03B1\\u05F3", "B",
"\\u03B1\\u05F3", UIDNA_ERROR_CONTEXTO_PUNCTUATION|UIDNA_ERROR_BIDI },
{ "\\u05F4", "B",
"\\u05F4", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
{ "l\\u30FB", "B",
"l\\u30FB", UIDNA_ERROR_CONTEXTO_PUNCTUATION },
// Ticket #8137: UTS #46 toUnicode() fails with non-ASCII labels that turn
// into 15 characters (UChars).
// The bug was in u_strFromPunycode() which did not write the last character
// if it just so fit into the end of the destination buffer.
// The UTS #46 code gives a default-capacity UnicodeString as the destination buffer,
// and the internal UnicodeString capacity is currently 15 UChars on 64-bit machines
// but 13 on 32-bit machines.
// Label with 15 UChars, for 64-bit-machine testing:
{ "aaaaaaaaaaaaa\\u00FCa.de", "B", "aaaaaaaaaaaaa\\u00FCa.de", 0 },
{ "xn--aaaaaaaaaaaaaa-ssb.de", "B", "aaaaaaaaaaaaa\\u00FCa.de", 0 },
{ "abschlu\\u00DFpr\\u00FCfung.de", "N", "abschlu\\u00DFpr\\u00FCfung.de", 0 },
{ "xn--abschluprfung-hdb15b.de", "B", "abschlu\\u00DFpr\\u00FCfung.de", 0 },
// Label with 13 UChars, for 32-bit-machine testing:
{ "xn--aaaaaaaaaaaa-nlb.de", "B", "aaaaaaaaaaa\\u00FCa.de", 0 },
{ "xn--schluprfung-z6a39a.de", "B", "schlu\\u00DFpr\\u00FCfung.de", 0 },
// { "", "B",
// "", 0 },
};
} // namespace
void UTS46Test::TestSomeCases() {
IcuTestErrorCode errorCode(*this, "TestSomeCases");
char buffer[400], buffer2[400];
int32_t i;
for(i=0; i<UPRV_LENGTHOF(testCases); ++i) {
const TestCase &testCase=testCases[i];
UnicodeString input(ctou(testCase.s));
UnicodeString expected(ctou(testCase.u));
// ToASCII/ToUnicode, transitional/nontransitional
UnicodeString aT, uT, aN, uN;
IDNAInfo aTInfo, uTInfo, aNInfo, uNInfo;
trans->nameToASCII(input, aT, aTInfo, errorCode);
trans->nameToUnicode(input, uT, uTInfo, errorCode);
nontrans->nameToASCII(input, aN, aNInfo, errorCode);
nontrans->nameToUnicode(input, uN, uNInfo, errorCode);
if(errorCode.errIfFailureAndReset("first-level processing [%d/%s] %s",
static_cast<int>(i), testCase.o, testCase.s)
) {
continue;
}
// ToUnicode does not set length-overflow errors.
uint32_t uniErrors=testCase.errors&~
(UIDNA_ERROR_LABEL_TOO_LONG|
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG);
char mode=testCase.o[0];
if(mode=='B' || mode=='N') {
if(uNInfo.getErrors()!=uniErrors) {
errln("N.nameToUnicode([%d] %s) unexpected errors %04lx",
static_cast<int>(i), testCase.s, static_cast<long>(uNInfo.getErrors()));
continue;
}
if(uN!=expected) {
prettify(uN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
errln("N.nameToUnicode([%d] %s) unexpected string %s",
static_cast<int>(i), testCase.s, buffer);
continue;
}
if(aNInfo.getErrors()!=testCase.errors) {
errln("N.nameToASCII([%d] %s) unexpected errors %04lx",
static_cast<int>(i), testCase.s, static_cast<long>(aNInfo.getErrors()));
continue;
}
}
if(mode=='B' || mode=='T') {
if(uTInfo.getErrors()!=uniErrors) {
errln("T.nameToUnicode([%d] %s) unexpected errors %04lx",
static_cast<int>(i), testCase.s, static_cast<long>(uTInfo.getErrors()));
continue;
}
if(uT!=expected) {
prettify(uT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
errln("T.nameToUnicode([%d] %s) unexpected string %s",
static_cast<int>(i), testCase.s, buffer);
continue;
}
if(aTInfo.getErrors()!=testCase.errors) {
errln("T.nameToASCII([%d] %s) unexpected errors %04lx",
static_cast<int>(i), testCase.s, static_cast<long>(aTInfo.getErrors()));
continue;
}
}
// ToASCII is all-ASCII if no severe errors
if((aNInfo.getErrors()&severeErrors)==0 && !isASCII(aN)) {
prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
errln("N.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
static_cast<int>(i), testCase.s, aNInfo.getErrors(), buffer);
continue;
}
if((aTInfo.getErrors()&severeErrors)==0 && !isASCII(aT)) {
prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
errln("T.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
static_cast<int>(i), testCase.s, aTInfo.getErrors(), buffer);
continue;
}
if(verbose) {
char m= mode=='B' ? mode : 'N';
prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
logln("%c.nameToASCII([%d] %s) (errors %04lx) result string: %s",
m, static_cast<int>(i), testCase.s, aNInfo.getErrors(), buffer);
if(mode!='B') {
prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
logln("T.nameToASCII([%d] %s) (errors %04lx) result string: %s",
static_cast<int>(i), testCase.s, aTInfo.getErrors(), buffer);
}
}
// second-level processing
UnicodeString aTuN, uTaN, aNuN, uNaN;
IDNAInfo aTuNInfo, uTaNInfo, aNuNInfo, uNaNInfo;
nontrans->nameToUnicode(aT, aTuN, aTuNInfo, errorCode);
nontrans->nameToASCII(uT, uTaN, uTaNInfo, errorCode);
nontrans->nameToUnicode(aN, aNuN, aNuNInfo, errorCode);
nontrans->nameToASCII(uN, uNaN, uNaNInfo, errorCode);
if(errorCode.errIfFailureAndReset("second-level processing [%d/%s] %s",
static_cast<int>(i), testCase.o, testCase.s)
) {
continue;
}
if(aN!=uNaN) {
prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
prettify(uNaN).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2));
errln("N.nameToASCII([%d] %s)!=N.nameToUnicode().N.nameToASCII() "
"(errors %04lx) %s vs. %s",
static_cast<int>(i), testCase.s, aNInfo.getErrors(), buffer, buffer2);
continue;
}
if(aT!=uTaN) {
prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
prettify(uTaN).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2));
errln("T.nameToASCII([%d] %s)!=T.nameToUnicode().N.nameToASCII() "
"(errors %04lx) %s vs. %s",
static_cast<int>(i), testCase.s, aNInfo.getErrors(), buffer, buffer2);
continue;
}
if(uN!=aNuN) {
prettify(uN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
prettify(aNuN).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2));
errln("N.nameToUnicode([%d] %s)!=N.nameToASCII().N.nameToUnicode() "
"(errors %04lx) %s vs. %s",
static_cast<int>(i), testCase.s, uNInfo.getErrors(), buffer, buffer2);
continue;
}
if(uT!=aTuN) {
prettify(uT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
prettify(aTuN).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2));
errln("T.nameToUnicode([%d] %s)!=T.nameToASCII().N.nameToUnicode() "
"(errors %04lx) %s vs. %s",
static_cast<int>(i), testCase.s, uNInfo.getErrors(), buffer, buffer2);
continue;
}
// labelToUnicode
UnicodeString aTL, uTL, aNL, uNL;
IDNAInfo aTLInfo, uTLInfo, aNLInfo, uNLInfo;
trans->labelToASCII(input, aTL, aTLInfo, errorCode);
trans->labelToUnicode(input, uTL, uTLInfo, errorCode);
nontrans->labelToASCII(input, aNL, aNLInfo, errorCode);
nontrans->labelToUnicode(input, uNL, uNLInfo, errorCode);
if(errorCode.errIfFailureAndReset("labelToXYZ processing [%d/%s] %s",
static_cast<int>(i), testCase.o, testCase.s)
) {
continue;
}
if (aN.indexOf(static_cast<char16_t>(0x2e)) < 0) {
if(aN!=aNL || aNInfo.getErrors()!=aNLInfo.getErrors()) {
prettify(aN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
prettify(aNL).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2));
errln("N.nameToASCII([%d] %s)!=N.labelToASCII() "
"(errors %04lx vs %04lx) %s vs. %s",
static_cast<int>(i), testCase.s, aNInfo.getErrors(), aNLInfo.getErrors(), buffer, buffer2);
continue;
}
} else {
if((aNLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
errln("N.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
static_cast<int>(i), testCase.s, static_cast<long>(aNLInfo.getErrors()));
continue;
}
}
if (aT.indexOf(static_cast<char16_t>(0x2e)) < 0) {
if(aT!=aTL || aTInfo.getErrors()!=aTLInfo.getErrors()) {
prettify(aT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
prettify(aTL).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2));
errln("T.nameToASCII([%d] %s)!=T.labelToASCII() "
"(errors %04lx vs %04lx) %s vs. %s",
static_cast<int>(i), testCase.s, aTInfo.getErrors(), aTLInfo.getErrors(), buffer, buffer2);
continue;
}
} else {
if((aTLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
errln("T.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
static_cast<int>(i), testCase.s, static_cast<long>(aTLInfo.getErrors()));
continue;
}
}
if (uN.indexOf(static_cast<char16_t>(0x2e)) < 0) {
if(uN!=uNL || uNInfo.getErrors()!=uNLInfo.getErrors()) {
prettify(uN).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
prettify(uNL).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2));
errln("N.nameToUnicode([%d] %s)!=N.labelToUnicode() "
"(errors %04lx vs %04lx) %s vs. %s",
static_cast<int>(i), testCase.s, uNInfo.getErrors(), uNLInfo.getErrors(), buffer, buffer2);
continue;
}
} else {
if((uNLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
errln("N.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
static_cast<int>(i), testCase.s, static_cast<long>(uNLInfo.getErrors()));
continue;
}
}
if (uT.indexOf(static_cast<char16_t>(0x2e)) < 0) {
if(uT!=uTL || uTInfo.getErrors()!=uTLInfo.getErrors()) {
prettify(uT).extract(0, 0x7fffffff, buffer, UPRV_LENGTHOF(buffer));
prettify(uTL).extract(0, 0x7fffffff, buffer2, UPRV_LENGTHOF(buffer2));
errln("T.nameToUnicode([%d] %s)!=T.labelToUnicode() "
"(errors %04lx vs %04lx) %s vs. %s",
static_cast<int>(i), testCase.s, uTInfo.getErrors(), uTLInfo.getErrors(), buffer, buffer2);
continue;
}
} else {
if((uTLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
errln("T.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
static_cast<int>(i), testCase.s, static_cast<long>(uTLInfo.getErrors()));
continue;
}
}
// Differences between transitional and nontransitional processing
if(mode=='B') {
if( aNInfo.isTransitionalDifferent() ||
aTInfo.isTransitionalDifferent() ||
uNInfo.isTransitionalDifferent() ||
uTInfo.isTransitionalDifferent() ||
aNLInfo.isTransitionalDifferent() ||
aTLInfo.isTransitionalDifferent() ||
uNLInfo.isTransitionalDifferent() ||
uTLInfo.isTransitionalDifferent()
) {
errln("B.process([%d] %s) isTransitionalDifferent()", static_cast<int>(i), testCase.s);
continue;
}
if( aN!=aT || uN!=uT || aNL!=aTL || uNL!=uTL ||
aNInfo.getErrors()!=aTInfo.getErrors() || uNInfo.getErrors()!=uTInfo.getErrors() ||
aNLInfo.getErrors()!=aTLInfo.getErrors() || uNLInfo.getErrors()!=uTLInfo.getErrors()
) {
errln("N.process([%d] %s) vs. T.process() different errors or result strings",
static_cast<int>(i), testCase.s);
continue;
}
} else {
if( !aNInfo.isTransitionalDifferent() ||
!aTInfo.isTransitionalDifferent() ||
!uNInfo.isTransitionalDifferent() ||
!uTInfo.isTransitionalDifferent() ||
!aNLInfo.isTransitionalDifferent() ||
!aTLInfo.isTransitionalDifferent() ||
!uNLInfo.isTransitionalDifferent() ||
!uTLInfo.isTransitionalDifferent()
) {
errln("%s.process([%d] %s) !isTransitionalDifferent()",
testCase.o, static_cast<int>(i), testCase.s);
continue;
}
if(aN==aT || uN==uT || aNL==aTL || uNL==uTL) {
errln("N.process([%d] %s) vs. T.process() same result strings",
static_cast<int>(i), testCase.s);
continue;
}
}
// UTF-8
std::string input8, aT8, uT8, aN8, uN8;
StringByteSink<std::string> aT8Sink(&aT8), uT8Sink(&uT8), aN8Sink(&aN8), uN8Sink(&uN8);
IDNAInfo aT8Info, uT8Info, aN8Info, uN8Info;
input.toUTF8String(input8);
trans->nameToASCII_UTF8(input8, aT8Sink, aT8Info, errorCode);
trans->nameToUnicodeUTF8(input8, uT8Sink, uT8Info, errorCode);
nontrans->nameToASCII_UTF8(input8, aN8Sink, aN8Info, errorCode);
nontrans->nameToUnicodeUTF8(input8, uN8Sink, uN8Info, errorCode);
if(errorCode.errIfFailureAndReset("UTF-8 processing [%d/%s] %s",
static_cast<int>(i), testCase.o, testCase.s)
) {
continue;
}
UnicodeString aT16(UnicodeString::fromUTF8(aT8));
UnicodeString uT16(UnicodeString::fromUTF8(uT8));
UnicodeString aN16(UnicodeString::fromUTF8(aN8));
UnicodeString uN16(UnicodeString::fromUTF8(uN8));
if( aN8Info.getErrors()!=aNInfo.getErrors() ||
uN8Info.getErrors()!=uNInfo.getErrors()
) {
errln("N.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx",
static_cast<int>(i), testCase.s,
static_cast<long>(aN8Info.getErrors()), static_cast<long>(aNInfo.getErrors()));
continue;
}
if( aT8Info.getErrors()!=aTInfo.getErrors() ||
uT8Info.getErrors()!=uTInfo.getErrors()
) {
errln("T.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx",
static_cast<int>(i), testCase.s,
static_cast<long>(aT8Info.getErrors()), static_cast<long>(aTInfo.getErrors()));
continue;
}
if(aT16!=aT || uT16!=uT || aN16!=aN || uN16!=uN) {
errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different string results",
testCase.o, static_cast<int>(i), testCase.s, static_cast<long>(aTInfo.getErrors()));
continue;
}
if( aT8Info.isTransitionalDifferent()!=aTInfo.isTransitionalDifferent() ||
uT8Info.isTransitionalDifferent()!=uTInfo.isTransitionalDifferent() ||
aN8Info.isTransitionalDifferent()!=aNInfo.isTransitionalDifferent() ||
uN8Info.isTransitionalDifferent()!=uNInfo.isTransitionalDifferent()
) {
errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different isTransitionalDifferent()",
testCase.o, static_cast<int>(i), testCase.s);
continue;
}
}
}
namespace {
const int32_t kNumFields = 7;
void U_CALLCONV
idnaTestLineFn(void *context,
char *fields[][2], int32_t /* fieldCount */,
UErrorCode *pErrorCode) {
reinterpret_cast<UTS46Test *>(context)->idnaTestOneLine(fields, *pErrorCode);
}
UnicodeString s16FromField(char *(&field)[2], const UnicodeString &sameAs) {
int32_t length = static_cast<int32_t>(field[1] - field[0]);
UnicodeString s = UnicodeString::fromUTF8(StringPiece(field[0], length)).trim().unescape();
if (s.isEmpty()) {
s = sameAs; // blank means same as another string
} else if (s == u"\"\"") {
s.remove(); // explicit empty string (new in Unicode 16)
}
return s;
}
std::string statusFromField(char *(&field)[2]) {
const char *start = u_skipWhitespace(field[0]);
std::string status;
if (start != field[1]) {
int32_t length = static_cast<int32_t>(field[1] - start);
while (length > 0 && (start[length - 1] == u' ' || start[length - 1] == u'\t')) {
--length;
}
status.assign(start, length);
}
return status;
}
} // namespace
void UTS46Test::checkIdnaTestResult(const char *line, const char *type,
const UnicodeString &expected, const UnicodeString &result,
const char *status, const IDNAInfo &info) {
// An error in toUnicode or toASCII is indicated by a value in square brackets,
// such as "[B5 B6]".
UBool expectedHasErrors = false;
if (*status != 0) {
if (*status != u'[') {
errln("%s status field does not start with '[': %s\n %s", type, status, line);
}
if (strcmp(status, reinterpret_cast<const char*>(u8"[]")) != 0) {
expectedHasErrors = true;
}
// ICU workaround:
// We do effectively VerifyDnsLength (we always check for lengths), except,
// based on past bug reports, we do not do the following in UTS #46 ToASCII:
// When VerifyDnsLength is true, the empty root label is disallowed.
// Ignore the expected error if it is the only one.
// TODO: ICU-22882 - Report the empty root label separately from empty non-root labels.
if (strncmp(type, "toASCII", 7) == 0 && // startsWith
strcmp(status, "[A4_2]") == 0 && !info.hasErrors()) {
if (result.endsWith(UnicodeString::readOnlyAlias(u".")) &&
// !contains
result.indexOf(UnicodeString::readOnlyAlias(u"..")) < 0) {
expectedHasErrors = false;
}
}
}
if (expectedHasErrors != info.hasErrors()) {
errln("%s expected errors %s %d != %d = actual has errors: %04lx\n %s",
type, status, expectedHasErrors, info.hasErrors(), static_cast<long>(info.getErrors()), line);
}
if (!expectedHasErrors && expected != result) {
errln("%s expected != actual\n %s", type, line);
errln(UnicodeString(u" ") + expected);
errln(UnicodeString(u" ") + result);
}
}
void UTS46Test::idnaTestOneLine(char *fields[][2], UErrorCode &errorCode) {
// IdnaTestV2.txt (since Unicode 11)
// Column 1: source
// The source string to be tested.
// "" means the empty string.
UnicodeString source = s16FromField(fields[0], UnicodeString());
// Column 2: toUnicode
// The result of applying toUnicode to the source, with Transitional_Processing=false.
// A blank value means the same as the source value.
// "" means the empty string.
UnicodeString toUnicode = s16FromField(fields[1], source);
// Column 3: toUnicodeStatus
// A set of status codes, each corresponding to a particular test.
// A blank value means [].
std::string toUnicodeStatus = statusFromField(fields[2]);
// Column 4: toAsciiN
// The result of applying toASCII to the source, with Transitional_Processing=false.
// A blank value means the same as the toUnicode value.
// "" means the empty string.
UnicodeString toAsciiN = s16FromField(fields[3], toUnicode);
// Column 5: toAsciiNStatus
// A set of status codes, each corresponding to a particular test.
// A blank value means the same as the toUnicodeStatus value.
std::string toAsciiNStatus = statusFromField(fields[4]);
if (toAsciiNStatus.empty()) {
toAsciiNStatus = toUnicodeStatus;
}
// Column 6: toAsciiT
// The result of applying toASCII to the source, with Transitional_Processing=true.
// A blank value means the same as the toAsciiN value.
// "" means the empty string.
UnicodeString toAsciiT = s16FromField(fields[5], toAsciiN);
// Column 7: toAsciiTStatus
// A set of status codes, each corresponding to a particular test.
// A blank value means the same as the toAsciiNStatus value.
std::string toAsciiTStatus = statusFromField(fields[6]);
if (toAsciiTStatus.empty()) {
toAsciiTStatus = toAsciiNStatus;
}
// ToASCII/ToUnicode, transitional/nontransitional
UnicodeString uN, aN, aT;
IDNAInfo uNInfo, aNInfo, aTInfo;
nontrans->nameToUnicode(source, uN, uNInfo, errorCode);
checkIdnaTestResult(fields[0][0], "toUnicodeNontrans", toUnicode, uN,
toUnicodeStatus.c_str(), uNInfo);
nontrans->nameToASCII(source, aN, aNInfo, errorCode);
checkIdnaTestResult(fields[0][0], "toASCIINontrans", toAsciiN, aN,
toAsciiNStatus.c_str(), aNInfo);
trans->nameToASCII(source, aT, aTInfo, errorCode);
checkIdnaTestResult(fields[0][0], "toASCIITrans", toAsciiT, aT,
toAsciiTStatus.c_str(), aTInfo);
}
namespace {
// TODO: de-duplicate
U_DEFINE_LOCAL_OPEN_POINTER(LocalStdioFilePointer, FILE, fclose);
} // namespace
void UTS46Test::IdnaTest() {
IcuTestErrorCode errorCode(*this, "IdnaTest");
const char *sourceTestDataPath = getSourceTestData(errorCode);
if (errorCode.errIfFailureAndReset("unable to find the source/test/testdata "
"folder (getSourceTestData())")) {
return;
}
CharString path(sourceTestDataPath, errorCode);
path.appendPathPart("IdnaTestV2.txt", errorCode);
LocalStdioFilePointer idnaTestFile(fopen(path.data(), "r"));
if (idnaTestFile.isNull()) {
errln("unable to open %s", path.data());
return;
}
// Columns (c1, c2,...) are separated by semicolons.
// Leading and trailing spaces and tabs in each column are ignored.
// Comments are indicated with hash marks.
char *fields[kNumFields][2];
u_parseDelimitedFile(path.data(), ';', fields, kNumFields, idnaTestLineFn, this, errorCode);
if (errorCode.errIfFailureAndReset("error parsing IdnaTestV2.txt")) {
return;
}
}
#endif // UCONFIG_NO_IDNA
|