diff --git a/crates/toml_edit/src/error.rs b/crates/toml_edit/src/error.rs index 6a278024..d0547e2c 100644 --- a/crates/toml_edit/src/error.rs +++ b/crates/toml_edit/src/error.rs @@ -31,7 +31,7 @@ impl TomlError { let len = if let Some((index, _)) = indices.next() { index } else { - raw.len() + raw.len() - offset }; let span = offset..(offset + len); diff --git a/crates/toml_edit/tests/testsuite/invalid.rs b/crates/toml_edit/tests/testsuite/invalid.rs index 79724163..12a4ba03 100644 --- a/crates/toml_edit/tests/testsuite/invalid.rs +++ b/crates/toml_edit/tests/testsuite/invalid.rs @@ -218,3 +218,12 @@ fn emoji_error_span() { let actual = &input[err.span().unwrap()]; assert_eq!(actual, input); } + +#[test] +fn text_error_span() { + let input = "asdf"; + let err = input.parse::().unwrap_err(); + dbg!(err.span()); + let actual = &input[err.span().unwrap()]; + assert_eq!(actual, ""); +}