From 589a43d6de18099fbd35c328dc244b020f02bc4d Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 15 Dec 2025 12:51:13 +0100 Subject: Forbid to .include something which is not a file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the next step coming from commit d64ed8c531b0 ("Do not allow empty strings on .include"). Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/parser.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'lib') 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. -- cgit v1.2.3