ICU-10883 UTS 46 toUnicode set error for empty label including just xn--

X-SVN-Rev: 36296
This commit is contained in:
Markus Scherer 2014-08-29 23:06:27 +00:00
parent b6b33e5481
commit 56e05e2809
2 changed files with 13 additions and 16 deletions

View File

@ -123,9 +123,7 @@ public final class UTS46 extends IDNA {
resetInfo(info);
int srcLength=src.length();
if(srcLength==0) {
if(toASCII) {
addError(info, Error.EMPTY_LABEL);
}
addError(info, Error.EMPTY_LABEL);
return dest;
}
// ASCII fastpath
@ -177,12 +175,11 @@ public final class UTS46 extends IDNA {
++i; // '.' was copied to dest already
break;
}
if(toASCII) {
if(i==labelStart) {
addLabelError(info, Error.EMPTY_LABEL);
} else if((i-labelStart)>63) {
addLabelError(info, Error.LABEL_TOO_LONG);
}
if(i==labelStart) {
addLabelError(info, Error.EMPTY_LABEL);
}
if(toASCII && (i-labelStart)>63) {
addLabelError(info, Error.LABEL_TOO_LONG);
}
promoteAndResetLabelErrors(info);
labelStart=i+1;
@ -357,9 +354,7 @@ public final class UTS46 extends IDNA {
}
// Validity check
if(labelLength==0) {
if(toASCII) {
addLabelError(info, Error.EMPTY_LABEL);
}
addLabelError(info, Error.EMPTY_LABEL);
return replaceLabel(dest, destLabelStart, destLabelLength, labelString, labelLength);
}
// labelLength>0

View File

@ -360,6 +360,7 @@ public class UTS46Test extends TestFmwk {
"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-"
@ -373,11 +374,13 @@ public class UTS46Test extends TestFmwk {
"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..c", "UIDNA_ERROR_EMPTY_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..c", "UIDNA_ERROR_EMPTY_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" },
@ -493,10 +496,10 @@ public class UTS46Test extends TestFmwk {
i, testCase.o, testCase.s, e));
continue;
}
// ToUnicode does not set length errors.
// ToUnicode does not set length-overflow errors.
uniErrors.clear();
uniErrors.addAll(testCase.errors);
uniErrors.removeAll(lengthErrors);
uniErrors.removeAll(lengthOverflowErrors);
char mode=testCase.o.charAt(0);
if(mode=='B' || mode=='N') {
if(!sameErrors(uNInfo, uniErrors)) {
@ -717,8 +720,7 @@ public class UTS46Test extends TestFmwk {
IDNA.Error.PUNYCODE,
IDNA.Error.LABEL_HAS_DOT,
IDNA.Error.INVALID_ACE_LABEL);
private static final EnumSet<IDNA.Error> lengthErrors=EnumSet.of(
IDNA.Error.EMPTY_LABEL,
private static final EnumSet<IDNA.Error> lengthOverflowErrors=EnumSet.of(
IDNA.Error.LABEL_TOO_LONG,
IDNA.Error.DOMAIN_NAME_TOO_LONG);