proofs.rs

A final bare tilde produces a diagnostic span past the end of the input

A final bare tilde produces a diagnostic span past the end of the input

Found in Report #41 v1 · Updated 2026-11-28 01:04 UTC

Description

ParseError::invalid_encoding_len reports two bytes for a final bare tilde,
even when called with the original string that produced the error.

Steps to Reproduce

Run this example with jsonptr 0.8.2.

use jsonptr::Pointer;

fn main() {
    let input = "/~";
    let error = Pointer::parse(input).unwrap_err();
    assert_eq!(error.complete_offset(), 1);
    assert_eq!(error.invalid_encoding_len(input), 1);
}
Expected Behavior

The diagnostic spans one byte because only the tilde remains at offset 1.

Actual Behavior

The last assertion fails because invalid_encoding_len returns 2. The span
would run from offset 1 to offset 3 in a two-byte string.

Environment

Rust 1.91.0 on aarch64 macOS. No optional jsonptr features are needed.

Change history
  1. v1 · created · 2026-11-28 01:04 UTC
    {
      "title": "A final bare tilde produces a diagnostic span past the end of the input",
      "body": "## Description\n\n`ParseError::invalid_encoding_len` reports two bytes for a final bare tilde,\neven when called with the original string that produced the error.\n\n## Steps to Reproduce\n\nRun this example with jsonptr 0.8.2.\n\n```rust\nuse jsonptr::Pointer;\n\nfn main() {\n    let input = \"/~\";\n    let error = Pointer::parse(input).unwrap_err();\n    assert_eq!(error.complete_offset(), 1);\n    assert_eq!(error.invalid_encoding_len(input), 1);\n}\n```\n\n## Expected Behavior\n\nThe diagnostic spans one byte because only the tilde remains at offset 1.\n\n## Actual Behavior\n\nThe last assertion fails because `invalid_encoding_len` returns 2. The span\nwould run from offset 1 to offset 3 in a two-byte string.\n\n## Environment\n\nRust 1.91.0 on aarch64 macOS. No optional jsonptr features are needed.",
      "validity": "reported",
      "upstream_status": "not_reported"
    }

Read and join the discussion on the report →