From f4dd4a2438c0000846a6bfd21d8b18dc47f280cf Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 13 Aug 2019 13:48:54 -0700 Subject: Fix error line/column when using CRLF line endings. --- src/de.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/de.rs b/src/de.rs index 234fa50..e71cd0c 100644 --- a/src/de.rs +++ b/src/de.rs @@ -1775,7 +1775,10 @@ impl<'a> Deserializer<'a> { /// All indexes are 0-based. fn to_linecol(&self, offset: usize) -> (usize, usize) { let mut cur = 0; - for (i, line) in self.input.lines().enumerate() { + // Use split_terminator instead of lines so that if there is a `\r`, + // it is included in the offset calculation. The `+1` values below + // account for the `\n`. + for (i, line) in self.input.split_terminator('\n').enumerate() { if cur + line.len() + 1 > offset { return (i, offset - cur); } -- cgit v1.2.3