diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2025-12-15 12:51:13 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2025-12-15 12:51:13 +0100 |
| commit | 589a43d6de18099fbd35c328dc244b020f02bc4d (patch) | |
| tree | 99d9df494e5189d0fa9e7c928729ce9d87604b9d /lib/xixanta | |
| parent | d64ed8c531b03a75d4e20d48f5d5f662898e60f7 (diff) | |
| download | tools.nes-589a43d6de18099fbd35c328dc244b020f02bc4d.tar.gz tools.nes-589a43d6de18099fbd35c328dc244b020f02bc4d.zip | |
Forbid to .include something which is not a file
This is the next step coming from commit d64ed8c531b0 ("Do not allow
empty strings on .include").
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib/xixanta')
| -rw-r--r-- | lib/xixanta/src/parser.rs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs index e227ade..68a80ad 100644 --- a/lib/xixanta/src/parser.rs +++ b/lib/xixanta/src/parser.rs @@ -923,19 +923,19 @@ impl Parser { // working directory. This way we construct the absolute path for the // given file. let file_path = self.fetch_path_from(node.args.as_ref().unwrap().first().unwrap())?; - if file_path.is_empty() { + let Some(current_source) = self.sources.get(self.current_source) else { + panic!("mismatch between the number of sources and the current one"); + }; + let abs_file = current_source.directory.join(file_path); + if !abs_file.is_file() { return Err(Error { line: node.value.line, global: false, - source: self.sources.get(self.current_source).unwrap().clone(), - message: ".include statement with an empty string".to_string(), + source: current_source.clone(), + message: ".include statements expect a file as the argument".to_string(), } .into()); } - let Some(current_source) = self.sources.get(self.current_source) else { - panic!("mismatch between the number of sources and the current one"); - }; - let abs_file = current_source.directory.join(file_path); // And open the file. This is the object to be passed as a reader for // the recursive `parse` call, but it also allows us to construct the @@ -2085,17 +2085,17 @@ mod tests { #[test] fn error_on_empty_include_string() { - let mut parser = Parser::default(); - let line = ".include \" \""; - - let err = parser - .parse(line.as_bytes(), &SourceInfo::default()) - .unwrap_err(); + for line in vec![".include \" \"", ".include \".\""].into_iter() { + let mut parser = Parser::default(); + let err = parser + .parse(line.as_bytes(), &SourceInfo::default()) + .unwrap_err(); - assert_eq!( - err.first().unwrap().message, - ".include statement with an empty string" - ); + assert_eq!( + err.first().unwrap().message, + ".include statements expect a file as the argument" + ); + } } // Regular instructions. |
