Fix font feature tag validation (#13542)

The previous implementation that I implemented had two issues:
1. It did not throw an error when the user input some invalid values
such as "panic".
2. The feature tag for OpenType fonts should be a combination of letters
and digits. We only checked if the input was an ASCII character, which
could lead to undefined behavior.

Closes #13517 

Release Notes:

- N/A
This commit is contained in:
张小白 2024-06-26 23:01:48 +08:00 committed by GitHub
parent d044dc8485
commit 18b4573064
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -58,7 +58,7 @@ impl<'de> serde::Deserialize<'de> for FontFeatures {
while let Some((key, value)) =
access.next_entry::<String, Option<FeatureValue>>()?
{
if key.len() != 4 && !key.is_ascii() {
if !is_valid_feature_tag(&key) {
log::error!("Incorrect font feature tag: {}", key);
continue;
}
@ -142,3 +142,15 @@ impl schemars::JsonSchema for FontFeatures {
schema.into()
}
}
fn is_valid_feature_tag(tag: &str) -> bool {
if tag.len() != 4 {
return false;
}
for ch in tag.chars() {
if !ch.is_ascii_alphanumeric() {
return false;
}
}
true
}