From: Ben Pfaff Date: Tue, 10 Jun 2025 16:21:00 +0000 (-0700) Subject: invalid variable names X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1187a05cf44d5ea2752aba9de79213d8e2119317;p=pspp invalid variable names --- diff --git a/rust/pspp/src/sys/cooked.rs b/rust/pspp/src/sys/cooked.rs index cb9de8fde2..0978487ae9 100644 --- a/rust/pspp/src/sys/cooked.rs +++ b/rust/pspp/src/sys/cooked.rs @@ -547,7 +547,9 @@ pub fn decode( .filter(|(_index, record)| record.width != RawWidth::Continuation) { let name = trim_end_spaces(input.name.to_string()); - let name = match Identifier::from_encoding(name, encoding) { + let name = match Identifier::from_encoding(name, encoding) + .and_then(Identifier::must_be_ordinary) + { Ok(name) => { if !dictionary.variables.contains(&name.0) { name diff --git a/rust/pspp/src/sys/test.rs b/rust/pspp/src/sys/test.rs index 3abb9cdc12..03cb14eda7 100644 --- a/rust/pspp/src/sys/test.rs +++ b/rust/pspp/src/sys/test.rs @@ -137,6 +137,11 @@ fn wrong_variable_positions() { test_sysfile("wrong_variable_positions"); } +#[test] +fn invalid_variable_name() { + test_sysfile("invalid_variable_name"); +} + fn test_sysfile(name: &str) { let input_filename = Path::new(env!("CARGO_MANIFEST_DIR")) .join("src/sys/testdata") diff --git a/rust/pspp/src/sys/testdata/invalid_variable_name.expected b/rust/pspp/src/sys/testdata/invalid_variable_name.expected new file mode 100644 index 0000000000..49475a8d64 --- /dev/null +++ b/rust/pspp/src/sys/testdata/invalid_variable_name.expected @@ -0,0 +1,29 @@ +"$UM1" may not be used as an identifier because it begins with disallowed character "$". Renaming variable to VAR001. + +"#UM1" may not be used as an identifier because it begins with disallowed character "#". Renaming variable to VAR002. + +"!UM1" may not be used as an identifier because it begins with disallowed character "!". Renaming variable to VAR003. + +"GE" may not be used as an identifier because it is a reserved word. Renaming variable to VAR004. + +╭──────────────────────┬────────────────────────╮ +│ Created │ 01-JAN-2011 20:53:52│ +├──────────────────────┼────────────────────────┤ +│Writer Product │PSPP synthetic test file│ +├──────────────────────┼────────────────────────┤ +│ Compression │SAV │ +│ Number of Cases│Unknown │ +╰──────────────────────┴────────────────────────╯ + +╭─────────┬─╮ +│Variables│4│ +╰─────────┴─╯ + +╭──────┬────────┬─────┬─────────────────┬─────┬─────┬─────────┬────────────┬────────────┬──────────────╮ +│ │Position│Label│Measurement Level│ Role│Width│Alignment│Print Format│Write Format│Missing Values│ +├──────┼────────┼─────┼─────────────────┼─────┼─────┼─────────┼────────────┼────────────┼──────────────┤ +│var001│ 1│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +│var002│ 2│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +│var003│ 3│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +│var004│ 4│ │ │Input│ 8│Right │F8.0 │F8.0 │ │ +╰──────┴────────┴─────┴─────────────────┴─────┴─────┴─────────┴────────────┴────────────┴──────────────╯ diff --git a/rust/pspp/src/sys/testdata/invalid_variable_name.sack b/rust/pspp/src/sys/testdata/invalid_variable_name.sack new file mode 100644 index 0000000000..d87cf14689 --- /dev/null +++ b/rust/pspp/src/sys/testdata/invalid_variable_name.sack @@ -0,0 +1,15 @@ +# File header. +"$FL2"; s60 "$(#) SPSS DATA FILE PSPP synthetic test file"; +2; 4; 1; 0; -1; 100.0; "01 Jan 11"; "20:53:52"; s64 ""; i8 0 *3; + +# Numeric variable. +2; 0; 0; 0; 0x050800 *2; s8 >>"$UM1"<<; +2; 0; 0; 0; 0x050800 *2; s8 >>"#UM1"<<; +2; 0; 0; 0; 0x050800 *2; s8 >>"!UM1"<<; +2; 0; 0; 0; 0x050800 *2; s8 >>"GE"<<; + +# Character encoding record. +7; 20; 1; 12; "windows-1252"; + +# End of dictionary. +999; 0;