Skip to content

Commit c6e90a3

Browse files
committed
👽️ deps: bump quick-xml to 0.38.0 and unescape manually
1 parent ca47083 commit c6e90a3

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

packages/biliass/rust/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/biliass/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pyo3 = { version = "0.25.0", features = ["abi3-py310"] }
1313
bytes = "1.10.0"
1414
prost = "0.14.0"
1515
thiserror = "2.0.11"
16-
quick-xml = "0.37.2"
16+
quick-xml = "0.38.0"
1717
cached = "0.55.0"
1818
serde = "1.0.218"
1919
serde_json = "1.0.139"

packages/biliass/rust/src/reader/xml.rs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,43 @@ fn parse_raw_p(reader: &mut Reader<&[u8]>, element: &BytesStart) -> Result<Strin
3030
}
3131

3232
fn parse_comment_content(reader: &mut Reader<&[u8]>) -> Result<String, ParseError> {
33-
let mut content = None;
33+
let mut contents = Vec::new();
3434
let mut buf = Vec::new();
3535

36-
if let Ok(Event::Text(e)) = reader.read_event_into(&mut buf) {
37-
content = Some(e.unescape().unwrap().into_owned());
36+
loop {
37+
match reader.read_event_into(&mut buf) {
38+
Ok(Event::Text(e)) => {
39+
contents.push(Some(e.decode().unwrap().into_owned()));
40+
}
41+
Ok(Event::GeneralRef(e)) => {
42+
let entity_str = std::str::from_utf8(e.as_ref())
43+
.map_err(|e| ParseError::Xml(format!("Error decoding entity: {e}")))?;
44+
let resolved_entity = quick_xml::escape::resolve_predefined_entity(entity_str)
45+
.ok_or_else(|| {
46+
ParseError::Xml(format!("Error resolving entity: {entity_str}"))
47+
})?;
48+
contents.push(Some(resolved_entity.to_string()));
49+
}
50+
Ok(Event::End(_) | Event::Eof) => {
51+
break;
52+
}
53+
Ok(_) => {
54+
// Ignore other events
55+
continue;
56+
}
57+
Err(e) => {
58+
return Err(ParseError::Xml(format!(
59+
"Error reading comment content: {e}"
60+
)));
61+
}
62+
}
3863
}
3964
buf.clear();
4065

41-
content.ok_or(ParseError::Xml("No content found in comment".to_string()))
66+
if contents.is_empty() {
67+
return Err(ParseError::Xml("No content found in comment".to_string()));
68+
}
69+
Ok(contents.into_iter().flatten().collect::<String>())
4270
}
4371

4472
fn parse_comment_item(
@@ -201,7 +229,7 @@ where
201229
"No version specified".to_string(),
202230
)));
203231
}
204-
if let Ok(comment_option) = parse_comment(
232+
match parse_comment(
205233
&mut reader,
206234
e,
207235
version.clone().unwrap(),
@@ -210,11 +238,18 @@ where
210238
count,
211239
block_options,
212240
) {
213-
if let Some(comment) = comment_option {
214-
comments.push(comment);
241+
Ok(comment_option) => {
242+
if let Some(comment) = comment_option {
243+
comments.push(comment);
244+
}
245+
}
246+
Err(e) => {
247+
eprintln!(
248+
"Error parsing comment at {:?}, {}",
249+
reader.buffer_position(),
250+
e
251+
);
215252
}
216-
} else {
217-
eprintln!("Error parsing comment at {:?}", reader.buffer_position());
218253
}
219254
count += 1;
220255
}

0 commit comments

Comments
 (0)