Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop quotes from names parsed from fea earlier so we detect empty ones correctly #1194

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fea-rs/src/compile/compile_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> {
platform_id,
encoding_id,
language_id,
string: node.string().text.clone(),
string: node.string().into(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion fea-rs/src/compile/tables/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl NameSpec {
}

pub fn build(&self, name_id: NameId) -> write_fonts::tables::name::NameRecord {
let string = parse_string(self.platform_id, self.string.trim_matches('"'));
let string = parse_string(self.platform_id, &self.string);
write_fonts::tables::name::NameRecord::new(
self.platform_id,
self.encoding_id,
Expand Down
2 changes: 1 addition & 1 deletion fea-rs/src/compile/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ impl<'a, V: VariationInfo> ValidationCtx<'a, V> {

let platform = platform.unwrap_or(WIN_PLATFORM_ID);

if let Err((range, err)) = validate_name_string_encoding(platform, spec.string()) {
if let Err((range, err)) = validate_name_string_encoding(platform, spec.string_token()) {
self.error(range, err);
}
if let Some((platspec, language)) = spec.platform_and_language_ids() {
Expand Down
18 changes: 18 additions & 0 deletions fea-rs/src/parse/grammar/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,22 @@ mod tests {
assert!(valrecord.advance().is_none());
assert!(valrecord.placement().is_some());
}

#[test]
fn name_string_omits_quotes() {
let parse_name = |fea| {
let (token, _err, _) = debug_parse_output(fea, |parser| {
expect_name_record(parser, TokenSet::EMPTY);
});

crate::typed::NameSpec::cast(&token).unwrap()
};
assert_eq!(
["", "duck"],
[
parse_name("3 1 0x409 \"\"").string(),
parse_name("3 1 0x409 \"duck\"").string(),
]
);
}
}
9 changes: 8 additions & 1 deletion fea-rs/src/token_tree/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,9 +1487,16 @@ impl NameSpec {
}
}

pub(crate) fn string(&self) -> &Token {
pub(crate) fn string_token(&self) -> &Token {
// There is always a string
self.find_token(Kind::String).unwrap()
}

pub(crate) fn string(&self) -> &str {
// The value is always doublequoted so slice out the actual string
let s = self.string_token().as_str();
&s[1..s.len() - 1]
}
}

impl DecOctHex {
Expand Down
Loading