Skip to content

Commit 21f82da

Browse files
committed
validate property names
1 parent 5ca4fd4 commit 21f82da

File tree

9 files changed

+645
-587
lines changed

9 files changed

+645
-587
lines changed

components/properties/src/bidi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl EnumeratedProperty for BidiMirroringGlyph {
2828
const SINGLETON: &'static crate::provider::PropertyCodePointMap<'static, Self> =
2929
crate::provider::Baked::SINGLETON_PROPERTY_ENUM_BIDI_MIRRORING_GLYPH_V1;
3030
const NAME: &'static [u8] = b"Bidi_Mirroring_Glyph";
31-
const SHORT_NAME: &'static [u8] = b"Bidi_Mirroring_Glyph";
31+
const SHORT_NAME: &'static [u8] = b"bmg";
3232
}
3333

3434
impl crate::private::Sealed for BidiMirroringGlyph {}

components/properties/src/emoji.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,8 @@ pub trait EmojiSet: crate::private::Sealed {
168168
#[doc(hidden)]
169169
#[cfg(feature = "compiled_data")]
170170
const SINGLETON: &'static PropertyUnicodeSet<'static>;
171+
/// The name of this property
172+
const NAME: &'static [u8];
173+
/// The abbreviated name of this property, if it exists, otherwise the name
174+
const SHORT_NAME: &'static [u8];
171175
}

components/properties/src/props.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,8 +1904,8 @@ make_binary_property! {
19041904
}
19051905

19061906
make_binary_property! {
1907-
name: "Alnum";
1908-
short_name: "Alnum";
1907+
name: "alnum";
1908+
short_name: "alnum";
19091909
ident: Alnum;
19101910
data_marker: crate::provider::PropertyBinaryAlnumV1;
19111911
singleton: SINGLETON_PROPERTY_BINARY_ALNUM_V1;
@@ -1986,8 +1986,8 @@ make_binary_property! {
19861986
}
19871987

19881988
make_binary_property! {
1989-
name: "Blank";
1990-
short_name: "Blank";
1989+
name: "blank";
1990+
short_name: "blank";
19911991
ident: Blank;
19921992
data_marker: crate::provider::PropertyBinaryBlankV1;
19931993
singleton: SINGLETON_PROPERTY_BINARY_BLANK_V1;
@@ -2430,8 +2430,8 @@ make_binary_property! {
24302430
}
24312431

24322432
make_binary_property! {
2433-
name: "Graph";
2434-
short_name: "Graph";
2433+
name: "graph";
2434+
short_name: "graph";
24352435
ident: Graph;
24362436
data_marker: crate::provider::PropertyBinaryGraphV1;
24372437
singleton: SINGLETON_PROPERTY_BINARY_GRAPH_V1;
@@ -2562,7 +2562,7 @@ make_binary_property! {
25622562
}
25632563

25642564
make_binary_property! {
2565-
name: "Id_Continue";
2565+
name: "ID_Continue";
25662566
short_name: "IDC";
25672567
ident: IdContinue;
25682568
data_marker: crate::provider::PropertyBinaryIdContinueV1;
@@ -2614,7 +2614,7 @@ make_binary_property! {
26142614
}
26152615

26162616
make_binary_property! {
2617-
name: "Id_Start";
2617+
name: "ID_Start";
26182618
short_name: "IDS";
26192619
ident: IdStart;
26202620
data_marker: crate::provider::PropertyBinaryIdStartV1;
@@ -2643,7 +2643,7 @@ make_binary_property! {
26432643
}
26442644

26452645
make_binary_property! {
2646-
name: "Ids_Binary_Operator";
2646+
name: "IDS_Binary_Operator";
26472647
short_name: "IDSB";
26482648
ident: IdsBinaryOperator;
26492649
data_marker: crate::provider::PropertyBinaryIdsBinaryOperatorV1;
@@ -2664,7 +2664,7 @@ make_binary_property! {
26642664
}
26652665

26662666
make_binary_property! {
2667-
name: "Ids_Trinary_Operator";
2667+
name: "IDS_Trinary_Operator";
26682668
short_name: "IDST";
26692669
ident: IdsTrinaryOperator;
26702670
data_marker: crate::provider::PropertyBinaryIdsTrinaryOperatorV1;
@@ -2819,7 +2819,7 @@ make_binary_property! {
28192819

28202820
make_binary_property! {
28212821
name: "NFC_Inert";
2822-
short_name: "NFC_Inert";
2822+
short_name: "nfcinert";
28232823
ident: NfcInert;
28242824
data_marker: crate::provider::PropertyBinaryNfcInertV1;
28252825
singleton: SINGLETON_PROPERTY_BINARY_NFC_INERT_V1;
@@ -2828,7 +2828,7 @@ make_binary_property! {
28282828

28292829
make_binary_property! {
28302830
name: "NFD_Inert";
2831-
short_name: "NFD_Inert";
2831+
short_name: "nfdinert";
28322832
ident: NfdInert;
28332833
data_marker: crate::provider::PropertyBinaryNfdInertV1;
28342834
singleton: SINGLETON_PROPERTY_BINARY_NFD_INERT_V1;
@@ -2837,7 +2837,7 @@ make_binary_property! {
28372837

28382838
make_binary_property! {
28392839
name: "NFKC_Inert";
2840-
short_name: "NFKC_Inert";
2840+
short_name: "nfkcinert";
28412841
ident: NfkcInert;
28422842
data_marker: crate::provider::PropertyBinaryNfkcInertV1;
28432843
singleton: SINGLETON_PROPERTY_BINARY_NFKC_INERT_V1;
@@ -2846,7 +2846,7 @@ make_binary_property! {
28462846

28472847
make_binary_property! {
28482848
name: "NFKD_Inert";
2849-
short_name: "NFKD_Inert";
2849+
short_name: "nfkdinert";
28502850
ident: NfkdInert;
28512851
data_marker: crate::provider::PropertyBinaryNfkdInertV1;
28522852
singleton: SINGLETON_PROPERTY_BINARY_NFKD_INERT_V1;
@@ -2917,8 +2917,8 @@ make_binary_property! {
29172917
}
29182918

29192919
make_binary_property! {
2920-
name: "Print";
2921-
short_name: "Print";
2920+
name: "print";
2921+
short_name: "print";
29222922
ident: Print;
29232923
data_marker: crate::provider::PropertyBinaryPrintV1;
29242924
singleton: SINGLETON_PROPERTY_BINARY_PRINT_V1;
@@ -3018,7 +3018,7 @@ make_binary_property! {
30183018

30193019
make_binary_property! {
30203020
name: "Segment_Starter";
3021-
short_name: "Segment_Starter";
3021+
short_name: "segstart";
30223022
ident: SegmentStarter;
30233023
data_marker: crate::provider::PropertyBinarySegmentStarterV1;
30243024
singleton: SINGLETON_PROPERTY_BINARY_SEGMENT_STARTER_V1;
@@ -3028,7 +3028,7 @@ make_binary_property! {
30283028

30293029
make_binary_property! {
30303030
name: "Case_Sensitive";
3031-
short_name: "Case_Sensitive";
3031+
short_name: "Sensitive";
30323032
ident: CaseSensitive;
30333033
data_marker: crate::provider::PropertyBinaryCaseSensitiveV1;
30343034
singleton: SINGLETON_PROPERTY_BINARY_CASE_SENSITIVE_V1;
@@ -3153,7 +3153,7 @@ make_binary_property! {
31533153

31543154
make_binary_property! {
31553155
name: "White_Space";
3156-
short_name: "space";
3156+
short_name: "WSpace";
31573157
ident: WhiteSpace;
31583158
data_marker: crate::provider::PropertyBinaryWhiteSpaceV1;
31593159
singleton: SINGLETON_PROPERTY_BINARY_WHITE_SPACE_V1;
@@ -3176,8 +3176,8 @@ make_binary_property! {
31763176
}
31773177

31783178
make_binary_property! {
3179-
name: "Xdigit";
3180-
short_name: "Xdigit";
3179+
name: "xdigit";
3180+
short_name: "xdigit";
31813181
ident: Xdigit;
31823182
data_marker: crate::provider::PropertyBinaryXdigitV1;
31833183
singleton: SINGLETON_PROPERTY_BINARY_XDIGIT_V1;
@@ -3247,6 +3247,8 @@ pub use crate::emoji::EmojiSet;
32473247

32483248
macro_rules! make_emoji_set {
32493249
(
3250+
name: $name:literal;
3251+
short_name: $short_name:literal;
32503252
ident: $ident:ident;
32513253
data_marker: $data_marker:ty;
32523254
singleton: $singleton:ident;
@@ -3264,11 +3266,15 @@ macro_rules! make_emoji_set {
32643266
#[cfg(feature = "compiled_data")]
32653267
const SINGLETON: &'static crate::provider::PropertyUnicodeSet<'static> =
32663268
&crate::provider::Baked::$singleton;
3269+
const NAME: &'static [u8] = $name.as_bytes();
3270+
const SHORT_NAME: &'static [u8] = $short_name.as_bytes();
32673271
}
32683272
}
32693273
}
32703274

32713275
make_emoji_set! {
3276+
name: "Basic_Emoji";
3277+
short_name: "Basic_Emoji";
32723278
ident: BasicEmoji;
32733279
data_marker: crate::provider::PropertyBinaryBasicEmojiV1;
32743280
singleton: SINGLETON_PROPERTY_BINARY_BASIC_EMOJI_V1;

provider/source/src/properties/bidi.rs

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@ use crate::SourceDataProvider;
88
use icu::properties::provider::PropertyEnumBidiMirroringGlyphV1;
99
use icu_provider::prelude::*;
1010

11-
#[cfg(any(feature = "use_wasm", feature = "use_icu4c"))]
12-
impl SourceDataProvider {
13-
fn get_code_point_prop_map<'a>(
14-
&'a self,
15-
key: &str,
16-
) -> Result<&'a super::uprops_serde::code_point_prop::CodePointPropertyMap, DataError> {
17-
self.icuexport()?
18-
.read_and_parse_toml::<super::uprops_serde::code_point_prop::Main>(&format!(
19-
"uprops/{}/{}.toml",
20-
self.trie_type(),
21-
key
22-
))?
23-
.enum_property
24-
.first()
25-
.ok_or_else(|| DataErrorKind::MarkerNotFound.into_error())
26-
}
27-
}
28-
2911
// implement data provider 2 different ways, based on whether or not
3012
// features exist that enable the use of CPT Builder (ex: `use_wasm` or `use_icu4c`)
3113
impl DataProvider<PropertyEnumBidiMirroringGlyphV1> for SourceDataProvider {
@@ -34,46 +16,40 @@ impl DataProvider<PropertyEnumBidiMirroringGlyphV1> for SourceDataProvider {
3416
&self,
3517
req: DataRequest,
3618
) -> Result<DataResponse<PropertyEnumBidiMirroringGlyphV1>, DataError> {
37-
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
38-
use icu::collections::codepointtrie::CodePointTrie;
3919
use icu::collections::codepointtrie::TrieType;
4020
use icu::collections::codepointtrie::TrieValue;
4121
use icu::properties::props::BidiMirroringGlyph;
4222
use icu::properties::props::BidiPairedBracketType;
23+
use icu::properties::props::EnumeratedProperty;
4324
use icu_codepointtrie_builder::{CodePointTrieBuilder, CodePointTrieBuilderData};
4425

4526
self.check_req::<PropertyEnumBidiMirroringGlyphV1>(req)?;
4627

47-
// Bidi_M / Bidi_Mirrored
48-
let bidi_m_data = self.get_binary_prop_for_code_point_set("Bidi_M")?;
49-
let mut bidi_m_builder = CodePointInversionListBuilder::new();
50-
for (start, end) in &bidi_m_data.ranges {
51-
bidi_m_builder.add_range32(start..=end);
52-
}
53-
let bidi_m_cpinvlist = bidi_m_builder.build();
54-
55-
// bmg / Bidi_Mirroring_Glyph
56-
let bmg_data = &self.get_code_point_prop_map("bmg")?.code_point_trie;
57-
let bmg_trie = CodePointTrie::try_from(bmg_data).map_err(|e| {
58-
DataError::custom("Could not parse CodePointTrie TOML").with_display_context(&e)
59-
})?;
60-
61-
// bpt / Bidi_Paired_Bracket_Type
62-
let bpt_data = &self.get_enumerated_prop("bpt")?.code_point_trie;
63-
let bpt_trie = CodePointTrie::try_from(bpt_data).map_err(|e| {
64-
DataError::custom("Could not parse CodePointTrie TOML").with_display_context(&e)
65-
})?;
28+
let bidi_m_cpinvlist = self
29+
.get_binary_prop_for_code_point_set("Bidi_Mirrored", "Bidi_M")?
30+
.build_inversion_list();
31+
32+
let bmg_trie = self
33+
.get_enumerated_prop(
34+
core::str::from_utf8(BidiMirroringGlyph::NAME).unwrap(),
35+
core::str::from_utf8(BidiMirroringGlyph::SHORT_NAME).unwrap(),
36+
)?
37+
.build_codepointtrie()?;
38+
39+
let bpt = self.get_enumerated_prop("Bidi_Paired_Bracket_Type", "bpt")?;
40+
let bpt_trie = bpt.build_codepointtrie::<u16>()?;
41+
let bpt_lookup = bpt.values_to_names_long();
6642

6743
let trie_vals = (0..=(char::MAX as u32)).map(|cp| {
6844
let mut r = BidiMirroringGlyph::default();
69-
r.mirrored = bidi_m_cpinvlist.contains32(cp);
70-
r.mirroring_glyph = r
71-
.mirrored
72-
.then_some(bmg_trie.get32(cp))
73-
.filter(|&cp| cp as u32 != 0);
74-
r.paired_bracket_type = match bpt_trie.get32(cp) {
75-
1 => BidiPairedBracketType::Open,
76-
2 => BidiPairedBracketType::Close,
45+
if !bidi_m_cpinvlist.contains32(cp) {
46+
return r;
47+
}
48+
r.mirrored = true;
49+
r.mirroring_glyph = Some(bmg_trie.get32(cp)).filter(|&cp| cp as u32 != 0);
50+
r.paired_bracket_type = match bpt_lookup[&(bpt_trie.get32(cp))] {
51+
"Open" => BidiPairedBracketType::Open,
52+
"Close" => BidiPairedBracketType::Close,
7753
_ => BidiPairedBracketType::None,
7854
};
7955
if r.mirrored && r.mirroring_glyph.is_none() {

0 commit comments

Comments
 (0)