mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
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:
parent
d044dc8485
commit
18b4573064
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user