mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 05:00:16 +00: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
1 changed files with 13 additions and 1 deletions
|
@ -58,7 +58,7 @@ impl<'de> serde::Deserialize<'de> for FontFeatures {
|
||||||
while let Some((key, value)) =
|
while let Some((key, value)) =
|
||||||
access.next_entry::<String, Option<FeatureValue>>()?
|
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);
|
log::error!("Incorrect font feature tag: {}", key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -142,3 +142,15 @@ impl schemars::JsonSchema for FontFeatures {
|
||||||
schema.into()
|
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 a new issue