aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2025-12-15 11:54:36 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2025-12-15 12:29:01 +0100
commitd64ed8c531b03a75d4e20d48f5d5f662898e60f7 (patch)
tree1c72b24a7d5acb4e99a9073f8862770e69547b6b /lib
parent4961b715328d43e721697457c35968618168760f (diff)
downloadtools.nes-d64ed8c531b0.tar.gz
tools.nes-d64ed8c531b0.zip
Do not allow empty strings on .include
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/xixanta/src/parser.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs
index 7a892b0..e227ade 100644
--- a/lib/xixanta/src/parser.rs
+++ b/lib/xixanta/src/parser.rs
@@ -923,6 +923,15 @@ 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() {
+ 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(),
+ }
+ .into());
+ }
let Some(current_source) = self.sources.get(self.current_source) else {
panic!("mismatch between the number of sources and the current one");
};
@@ -2074,6 +2083,21 @@ 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();
+
+ assert_eq!(
+ err.first().unwrap().message,
+ ".include statement with an empty string"
+ );
+ }
+
// Regular instructions.
#[test]