Skip to content
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
5 changes: 4 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,10 @@ fn parse_file_attribute(line: Chars) -> Result<FileAttribute, ContentError> {
args.first().map(|value| parse_ident(value)).transpose()?,
)),
(".CreationDate", args, 1) => Ok(FileAttribute::CreationDate(parse_date_time(args[0])?)),
(".GenerationSoftware", args, len) if len <= 3 => {
// Vendor and application are mandatory; anything shorter falls
// through to a user-defined attribute instead of indexing past the
// arguments.
(".GenerationSoftware", args, len) if (2..=3).contains(&len) => {
Ok(FileAttribute::GenerationSoftware(GenerationSoftware {
vendor: args[0].to_string(),
application: args[1].to_string(),
Expand Down
21 changes: 21 additions & 0 deletions tests/component_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4055,3 +4055,24 @@ fn malformed_aperture_definition() {
} if type_str.eq("T") && content.eq("%ADD10T*%")
));
}

/// A `.GenerationSoftware` file attribute with fewer than the mandatory vendor and
/// application values must not panic; it is kept as a user-defined attribute.
#[test]
fn generation_software_with_one_value_does_not_panic() {
// given
logging_init();

let reader = gerber_to_reader("%FSLAX23Y23*%\n%MOMM*%\n%TF.GenerationSoftware,KiCad*%\nM02*\n");

// when
let doc = parse(reader).unwrap();

// then
assert!(doc.commands.iter().any(|c| matches!(
c,
Ok(Command::ExtendedCode(ExtendedCode::FileAttribute(
FileAttribute::UserDefined { name, .. }
))) if name == ".GenerationSoftware"
)));
}
Loading