Skip to content

Commit f068b26

Browse files
authored
Fix misparsing of old binary defaults (#1029)
1 parent 4f610eb commit f068b26

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

unicodetools/src/main/java/org/unicode/props/PropertyParsingInfo.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.unicode.props.IndexUnicodeProperties.DefaultValueType;
2727
import org.unicode.props.PropertyUtilities.Merge;
2828
import org.unicode.props.UcdLineParser.IntRange;
29+
import org.unicode.props.UcdLineParser.UcdLine.Contents;
2930
import org.unicode.text.utility.Settings;
3031
import org.unicode.text.utility.Utility;
3132

@@ -771,19 +772,53 @@ private static void parsePropertyValueFile(
771772
// file: " + propInfo);
772773
// }
773774
String value;
774-
if (line.getParts().length == 2) {
775-
assert propInfo.property.getType() == PropertyType.Binary;
775+
// The file emoji-sequences.txt has a comment-like field after the binary property.
776+
if (line.getParts().length == 2
777+
|| filename.equals("emoji/*/emoji-sequences")
778+
|| filename.equals("emoji/*/emoji-zwj-sequences")) {
779+
if (propInfo.property.getType() != PropertyType.Binary) {
780+
throw new IllegalArgumentException(
781+
"Expected a value for "
782+
+ propInfo.property.getType()
783+
+ " property "
784+
+ propName);
785+
}
776786
value = "Yes";
777787
} else {
778-
value =
779-
propInfo.property.getType() == PropertyType.Binary
780-
? "Yes"
781-
: line.getParts()[2];
788+
value = line.getParts()[2];
789+
if (propInfo.property.getType() == PropertyType.Binary) {
790+
if (line.getType() == Contents.DATA
791+
&& UcdPropertyValues.Binary.forName(value)
792+
!= UcdPropertyValues.Binary.Yes) {
793+
// Most binary properties have no value field, but at least kEH_NoRotate has
794+
// Y.
795+
throw new IllegalArgumentException(
796+
"Unexpected value "
797+
+ value
798+
+ " for binary property "
799+
+ propName
800+
+ " in "
801+
+ filename);
802+
} else if (line.getType() == Contents.MISSING
803+
&& UcdPropertyValues.Binary.forName(value)
804+
!= UcdPropertyValues.Binary.No) {
805+
throw new IllegalArgumentException(
806+
"Unexpected default "
807+
+ value
808+
+ " for binary property "
809+
+ propName
810+
+ " in "
811+
+ filename);
812+
}
813+
}
782814
// The value should not be an empty string.
783815
// Exception: NFKC_Casefold does remove some characters by mapping them to nothing.
784-
assert !value.isEmpty()
785-
|| propInfo.property == UcdProperty.NFKC_Casefold
786-
|| propInfo.property == UcdProperty.NFKC_Simple_Casefold;
816+
if (value.isEmpty()
817+
&& !(propInfo.property == UcdProperty.NFKC_Casefold
818+
|| propInfo.property == UcdProperty.NFKC_Simple_Casefold)) {
819+
throw new IllegalArgumentException(
820+
"Unexpected empty value for property " + propName);
821+
}
787822
if (propInfo.property == UcdProperty.kMandarin) {
788823
if (indexUnicodeProperties.oldVersion) {
789824
value =

0 commit comments

Comments
 (0)