Fix font feature tag validation (#13542)

张小白 created

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

Change summary

crates/gpui/src/text_system/font_features.rs | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

Detailed changes

crates/gpui/src/text_system/font_features.rs 🔗

@@ -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
+}