Skip to content

Commit

Permalink
fix check_file() / check_buffer() which were broken if the header con…
Browse files Browse the repository at this point in the history
…tained a comment

this was broken by commit ec2119e: allow comments to be attached to elements
  • Loading branch information
DanielT committed Feb 1, 2024
1 parent 05ec1b3 commit aff1503
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions autosar-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,14 @@ mod test {

// file containing a valid arxml header -> true
let header = r#"<?xml version="1.0" encoding="utf-8"?>
<!-- comment --><!-- comment 2 -->
<AUTOSAR xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00050.xsd" xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">"#;
let arxml_file = dir.path().with_file_name("file.arxml");
File::create(&arxml_file)
.and_then(|mut file| file.write(header.as_bytes()))
.unwrap();
assert!(check_file(arxml_file));

assert!(check_buffer(header.as_bytes()));
}
}
7 changes: 6 additions & 1 deletion autosar-data/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,12 @@ impl<'a> ArxmlParser<'a> {
let mut lexer = ArxmlLexer::new(self.buffer, self.filename.clone());

if let Ok(ArxmlEvent::ArxmlHeader(_)) = self.next(&mut lexer) {
if let Ok(ArxmlEvent::BeginElement(elemname, attributes_text)) = self.next(&mut lexer) {
// skip any comments
let mut arxmlevent = self.next(&mut lexer);
while let Ok(ArxmlEvent::Comment(..)) = arxmlevent {
arxmlevent = self.next(&mut lexer);
}
if let Ok(ArxmlEvent::BeginElement(elemname, attributes_text)) = arxmlevent {
if let Ok(ElementName::Autosar) = ElementName::from_bytes(elemname) {
if let Ok(attributes) = self.parse_attribute_text(ElementType::ROOT, attributes_text) {
if self.parse_file_header(&attributes).is_ok() {
Expand Down

0 comments on commit aff1503

Please sign in to comment.