Skip to content

Commit 968d927

Browse files
committed
Stop at the > in PiParser which is consistent with other search functions
The parser search the end of processing instruction and this is the last byte of it
1 parent 385a1f8 commit 968d927

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

src/reader/buffered_reader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ macro_rules! impl_buffered_source {
115115

116116
match parser.feed(available) {
117117
Some(i) => {
118-
// We does not include `>` in data
119-
buf.extend_from_slice(&available[..i - 1]);
118+
buf.extend_from_slice(&available[..i]);
120119
done = true;
121-
i
120+
// +1 for `>` which we do not include
121+
i + 1
122122
}
123123
None => {
124124
buf.extend_from_slice(available);

src/reader/pi.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/// After successful search the parser will return [`Some`] with position where
77
/// processing instruction is ended (the position after `?>`). If search was
88
/// unsuccessful, a [`None`] will be returned. You typically would expect positive
9-
/// result of search, so that you should feed new data until yo'll get it.
9+
/// result of search, so that you should feed new data until you get it.
1010
///
1111
/// NOTE: after successful match the parser does not returned to the initial
1212
/// state and should not be used anymore. Create a new parser if you want to perform
@@ -25,9 +25,9 @@
2525
/// // ...get new chunk of data
2626
/// assert_eq!(parser.feed(b" with = 'some > and ?"), None);
2727
/// // ...get another chunk of data
28-
/// assert_eq!(parser.feed(b"' inside?>and the text follow..."), Some(10));
29-
/// // ^ ^
30-
/// // 0 10
28+
/// assert_eq!(parser.feed(b"' inside?>and the text follow..."), Some(9));
29+
/// // ^ ^
30+
/// // 0 9
3131
/// ```
3232
///
3333
/// [`feed`]: Self::feed()
@@ -56,11 +56,9 @@ impl PiParser {
5656
pub fn feed(&mut self, bytes: &[u8]) -> Option<usize> {
5757
for i in memchr::memchr_iter(b'>', bytes) {
5858
match i {
59-
// +1 for `>` which should be included in event
60-
0 if self.0 => return Some(1),
59+
0 if self.0 => return Some(0),
6160
// If the previous byte is `?`, then we found `?>`
62-
// +1 for `>` which should be included in event
63-
i if i > 0 && bytes[i - 1] == b'?' => return Some(i + 1),
61+
i if i > 0 && bytes[i - 1] == b'?' => return Some(i),
6462
_ => {}
6563
}
6664
}
@@ -95,11 +93,11 @@ fn pi() {
9593
assert_eq!(parse_pi(b"?", true), Err(true)); // ?|?
9694

9795
assert_eq!(parse_pi(b">", false), Err(false)); // x|>
98-
assert_eq!(parse_pi(b">", true), Ok(1)); // ?|>
96+
assert_eq!(parse_pi(b">", true), Ok(0)); // ?|>
9997

100-
assert_eq!(parse_pi(b"?>", false), Ok(2)); // x|?>
101-
assert_eq!(parse_pi(b"?>", true), Ok(2)); // ?|?>
98+
assert_eq!(parse_pi(b"?>", false), Ok(1)); // x|?>
99+
assert_eq!(parse_pi(b"?>", true), Ok(1)); // ?|?>
102100

103-
assert_eq!(parse_pi(b">?>", false), Ok(3)); // x|>?>
104-
assert_eq!(parse_pi(b">?>", true), Ok(1)); // ?|>?>
101+
assert_eq!(parse_pi(b">?>", false), Ok(2)); // x|>?>
102+
assert_eq!(parse_pi(b">?>", true), Ok(0)); // ?|>?>
105103
}

src/reader/slice_reader.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
279279
let mut parser = PiParser::default();
280280

281281
if let Some(i) = parser.feed(self) {
282-
*position += i;
283-
// We does not include `>` in data
284-
let bytes = &self[..i - 1];
285-
*self = &self[i..];
282+
// +1 for `>` which we do not include
283+
*position += i + 1;
284+
let bytes = &self[..i];
285+
*self = &self[i + 1..];
286286
Ok((bytes, true))
287287
} else {
288288
*position += self.len();

0 commit comments

Comments
 (0)