Skip to content

Commit 4f5f9e6

Browse files
committed
fix: properly parse xml with no replacements
1 parent d8d252d commit 4f5f9e6

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cpp-linter/src/clang_tools/clang_format.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use crate::{
1818
common_fs::{FileObj, get_line_count_from_offset},
1919
};
2020

21-
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
21+
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Default)]
2222
pub struct FormatAdvice {
2323
/// A list of [`Replacement`]s that clang-tidy wants to make.
24-
#[serde(rename(deserialize = "replacement"))]
24+
#[serde(rename(deserialize = "replacement"), default)]
2525
pub replacements: Vec<Replacement>,
2626

2727
pub patched: Option<Vec<u8>>,
@@ -196,6 +196,22 @@ mod tests {
196196
assert!(result.is_err());
197197
}
198198

199+
#[test]
200+
fn parse_xml_no_replacements() {
201+
let xml_raw = r#"<?xml version='1.0'?>
202+
<replacements xml:space='preserve' incomplete_format='false'>
203+
</replacements>"#
204+
.as_bytes()
205+
.to_vec();
206+
let expected = FormatAdvice {
207+
replacements: vec![],
208+
patched: None,
209+
};
210+
let xml = String::from_utf8(xml_raw).unwrap();
211+
let document = quick_xml::de::from_str::<FormatAdvice>(&xml).unwrap();
212+
assert_eq!(expected, document);
213+
}
214+
199215
#[test]
200216
fn parse_xml() {
201217
let xml_raw = r#"<?xml version='1.0'?>

0 commit comments

Comments
 (0)