Skip to content

Commit 64c4249

Browse files
authored
Merge pull request #679 from Mingun/fix-622
Fix wrong disregarding of not closed markup, such as lone `<`
2 parents f3e8b1f + 8d7913f commit 64c4249

File tree

7 files changed

+166
-161
lines changed

7 files changed

+166
-161
lines changed

Changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ configuration is serializable.
2323

2424
### Bug Fixes
2525

26+
- [#622]: Fix wrong disregarding of not closed markup, such as lone `<`.
27+
2628
### Misc Changes
2729

2830
- [#675]: Minimum supported version of serde raised to 1.0.139
@@ -36,6 +38,7 @@ configuration is serializable.
3638
- `Error::UnexpectedToken` replaced by `IllFormedError::DoubleHyphenInComment`
3739

3840
[#513]: https://github.com/tafia/quick-xml/issues/513
41+
[#622]: https://github.com/tafia/quick-xml/issues/622
3942
[#675]: https://github.com/tafia/quick-xml/pull/675
4043
[#677]: https://github.com/tafia/quick-xml/pull/677
4144

src/reader/async_tokio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
55
use tokio::io::{self, AsyncBufRead, AsyncBufReadExt};
66

7+
use crate::errors::{Error, Result, SyntaxError};
78
use crate::events::Event;
89
use crate::name::{QName, ResolveResult};
910
use crate::reader::buffered_reader::impl_buffered_source;
1011
use crate::reader::{
1112
is_whitespace, BangType, NsReader, ParseState, ReadElementState, Reader, Span,
1213
};
13-
use crate::{Error, Result};
1414

1515
/// A struct for read XML asynchronously from an [`AsyncBufRead`].
1616
///

src/reader/buffered_reader.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::Path;
77

88
use memchr;
99

10-
use crate::errors::{Error, Result};
10+
use crate::errors::{Error, Result, SyntaxError};
1111
use crate::events::Event;
1212
use crate::name::QName;
1313
use crate::reader::{is_whitespace, BangType, ReadElementState, Reader, Span, XmlSource};
@@ -54,7 +54,7 @@ macro_rules! impl_buffered_source {
5454
byte: u8,
5555
buf: &'b mut Vec<u8>,
5656
position: &mut usize,
57-
) -> Result<Option<&'b [u8]>> {
57+
) -> Result<(&'b [u8], bool)> {
5858
// search byte must be within the ascii range
5959
debug_assert!(byte.is_ascii());
6060

@@ -90,18 +90,14 @@ macro_rules! impl_buffered_source {
9090
}
9191
*position += read;
9292

93-
if read == 0 {
94-
Ok(None)
95-
} else {
96-
Ok(Some(&buf[start..]))
97-
}
93+
Ok((&buf[start..], done))
9894
}
9995

10096
$($async)? fn read_bang_element $(<$lf>)? (
10197
&mut self,
10298
buf: &'b mut Vec<u8>,
10399
position: &mut usize,
104-
) -> Result<Option<(BangType, &'b [u8])>> {
100+
) -> Result<(BangType, &'b [u8])> {
105101
// Peeked one bang ('!') before being called, so it's guaranteed to
106102
// start with it.
107103
let start = buf.len();
@@ -115,7 +111,7 @@ macro_rules! impl_buffered_source {
115111
match self $(.$reader)? .fill_buf() $(.$await)? {
116112
// Note: Do not update position, so the error points to
117113
// somewhere sane rather than at the EOF
118-
Ok(n) if n.is_empty() => return Err(bang_type.to_err()),
114+
Ok(n) if n.is_empty() => break,
119115
Ok(available) => {
120116
// We only parse from start because we don't want to consider
121117
// whatever is in the buffer before the bang element
@@ -126,7 +122,7 @@ macro_rules! impl_buffered_source {
126122
read += used;
127123

128124
*position += read;
129-
break;
125+
return Ok((bang_type, &buf[start..]));
130126
} else {
131127
buf.extend_from_slice(available);
132128

@@ -143,19 +139,15 @@ macro_rules! impl_buffered_source {
143139
}
144140
}
145141

146-
if read == 0 {
147-
Ok(None)
148-
} else {
149-
Ok(Some((bang_type, &buf[start..])))
150-
}
142+
Err(bang_type.to_err())
151143
}
152144

153145
#[inline]
154146
$($async)? fn read_element $(<$lf>)? (
155147
&mut self,
156148
buf: &'b mut Vec<u8>,
157149
position: &mut usize,
158-
) -> Result<Option<&'b [u8]>> {
150+
) -> Result<&'b [u8]> {
159151
let mut state = ReadElementState::Elem;
160152
let mut read = 0;
161153

@@ -172,7 +164,7 @@ macro_rules! impl_buffered_source {
172164

173165
// Position now just after the `>` symbol
174166
*position += read;
175-
break;
167+
return Ok(&buf[start..]);
176168
} else {
177169
// The `>` symbol not yet found, continue reading
178170
buf.extend_from_slice(available);
@@ -190,11 +182,7 @@ macro_rules! impl_buffered_source {
190182
};
191183
}
192184

193-
if read == 0 {
194-
Ok(None)
195-
} else {
196-
Ok(Some(&buf[start..]))
197-
}
185+
Err(Error::Syntax(SyntaxError::UnclosedTag))
198186
}
199187

200188
$($async)? fn skip_whitespace(&mut self, position: &mut usize) -> Result<()> {

0 commit comments

Comments
 (0)