Skip to content

Commit

Permalink
Fix #3900: return an error if the index is greater than MAX_PLACE_HOL…
Browse files Browse the repository at this point in the history
…DER_INDEX (#4318)
  • Loading branch information
younies authored Nov 16, 2023
1 parent 01e79c2 commit 4e642d4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions provider/datagen/src/transform/cldr/currency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ fn extract_currency_essentials<'data>(
PlaceholderValue::ISO
} else {
let index = place_holders.len() as u16;
//TODO(#3900): remove this assert and return an error instead.
assert!(index <= MAX_PLACE_HOLDER_INDEX);
place_holders.push(short_place_holder.as_str());
place_holders_checker_map.insert(short_place_holder.as_str(), index);
PlaceholderValue::Index(index)
Expand All @@ -157,14 +155,28 @@ fn extract_currency_essentials<'data>(
PlaceholderValue::ISO
} else {
let index = place_holders.len() as u16;
//TODO(#3900): remove this assert and return an error instead.
assert!(index <= MAX_PLACE_HOLDER_INDEX);
place_holders.push(narrow_place_holder.as_ref());
place_holders_checker_map.insert(narrow_place_holder.as_str(), index);
PlaceholderValue::Index(index)
}
});

// Ensure that short_place_holder_index and narrow_place_holder_index do not exceed MAX_PLACE_HOLDER_INDEX.
if let Some(PlaceholderValue::Index(index)) = short_place_holder_index {
if index > MAX_PLACE_HOLDER_INDEX {
return Err(DataError::custom(
"short_place_holder_index exceeded MAX_PLACE_HOLDER_INDEX",
));
}
}
if let Some(PlaceholderValue::Index(index)) = narrow_place_holder_index {
if index > MAX_PLACE_HOLDER_INDEX {
return Err(DataError::custom(
"narrow_place_holder_index exceeded MAX_PLACE_HOLDER_INDEX",
));
}
}

let iso_string = iso.try_into_tinystr().unwrap().to_string();

let short_pattern_standard: PatternSelection = if standard_alpha_next_to_number.is_empty() {
Expand Down

0 comments on commit 4e642d4

Please sign in to comment.