Skip to content

Commit 52d6ab3

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 52d6ab3

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
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: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
@@ -57,10 +57,9 @@ impl PiParser {
5757
for i in memchr::memchr_iter(b'>', bytes) {
5858
match i {
5959
// +1 for `>` which should be included in event
60-
0 if self.0 => return Some(1),
60+
0 if self.0 => return Some(0),
6161
// 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),
62+
i if i > 0 && bytes[i - 1] == b'?' => return Some(i),
6463
_ => {}
6564
}
6665
}
@@ -95,11 +94,11 @@ fn pi() {
9594
assert_eq!(parse_pi(b"?", true), Err(true)); // ?|?
9695

9796
assert_eq!(parse_pi(b">", false), Err(false)); // x|>
98-
assert_eq!(parse_pi(b">", true), Ok(1)); // ?|>
97+
assert_eq!(parse_pi(b">", true), Ok(0)); // ?|>
9998

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

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

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)