proofs.rs

Pointer::strip_prefix still returns a malformed Pointer in 0.8.2

Pointer::strip_prefix still returns a malformed Pointer in 0.8.2

Reported Fix proposed (author reported)

Found in Report #41 v1 · Updated 2026-11-28 06:15 UTC

I can reproduce the partial-token prefix bug from https://github.com/chanced/jsonptr/issues/131 in jsonptr 0.8.2.
Pointer::strip_prefix returns a Pointer whose string fails the crate's
own parser.

use jsonptr::Pointer;

fn main() {
    let pointer = Pointer::from_static("/ab");
    let prefix = Pointer::from_static("/a");
    assert!(pointer.strip_prefix(prefix).is_none());
}

The assertion fails because the result is Some containing "b". The
pointer has one token, ab, so there is no initial token a to remove.
pointer.starts_with(prefix) already returns false.

The open, unreleased pull request https://github.com/chanced/jsonptr/pull/132 adds the missing separator check, which would make this example return None.

Reproduced with Rust 1.91.0 on aarch64 macOS in debug and release.

Change history
  1. v1 · created · 2026-11-28 01:04 UTC
    {
      "title": "Pointer::strip_prefix still returns a malformed Pointer in 0.8.2",
      "body": "I can reproduce the partial-token prefix bug from https://github.com/chanced/jsonptr/issues/131 in jsonptr 0.8.2.\n`Pointer::strip_prefix` returns a `Pointer` whose string fails the crate's\nown parser.\n\n```rust\nuse jsonptr::Pointer;\n\nfn main() {\n    let pointer = Pointer::from_static(\"/ab\");\n    let prefix = Pointer::from_static(\"/a\");\n    assert!(pointer.strip_prefix(prefix).is_none());\n}\n```\n\nThe assertion fails because the result is `Some` containing `\"b\"`. The\npointer has one token, `ab`, so there is no initial token `a` to remove.\n`pointer.starts_with(prefix)` already returns `false`.\n\nReproduced with Rust 1.91.0 on aarch64 macOS in debug and release.",
      "validity": "reported",
      "upstream_status": "not_reported"
    }
  2. v2 · link_added · 2026-11-28 06:13 UTC
    {
      "id": "9885a95e-3d63-4712-9118-e6b916c263b5",
      "kind": "issue",
      "url": "https://github.com/chanced/jsonptr/issues/131",
      "version": null,
      "target_report_id": null,
      "target_revision_no": null,
      "edit_version": 1
    }
  3. v3 · link_added · 2026-11-28 06:13 UTC
    {
      "id": "0c52b235-5929-4ddf-84e4-e3affb04d9e9",
      "kind": "pr",
      "url": "https://github.com/chanced/jsonptr/pull/132",
      "version": null,
      "target_report_id": null,
      "target_revision_no": null,
      "edit_version": 2
    }
  4. v4 · edited · 2026-11-28 06:14 UTC
    {
      "title": "Pointer::strip_prefix still returns a malformed Pointer in 0.8.2",
      "evidence_url": null,
      "api_item_ids": [],
      "validity": "reported",
      "upstream_status": "fix_proposed",
      "duplicate_of": null,
      "edit_version": 3
    }
  5. v5 · edited · 2026-11-28 06:15 UTC
    {
      "title": "Pointer::strip_prefix still returns a malformed Pointer in 0.8.2",
      "body": "I can reproduce the partial-token prefix bug from https://github.com/chanced/jsonptr/issues/131 in jsonptr 0.8.2.\r\n`Pointer::strip_prefix` returns a `Pointer` whose string fails the crate's\r\nown parser.\r\n\r\n```rust\r\nuse jsonptr::Pointer;\r\n\r\nfn main() {\r\n    let pointer = Pointer::from_static(\"/ab\");\r\n    let prefix = Pointer::from_static(\"/a\");\r\n    assert!(pointer.strip_prefix(prefix).is_none());\r\n}\r\n```\r\n\r\nThe assertion fails because the result is `Some` containing `\"b\"`. The\r\npointer has one token, `ab`, so there is no initial token `a` to remove.\r\n`pointer.starts_with(prefix)` already returns `false`.\r\n\r\nThe open, unreleased pull request https://github.com/chanced/jsonptr/pull/132 adds the missing separator check, which would make this example return None.\r\n\r\nReproduced with Rust 1.91.0 on aarch64 macOS in debug and release.",
      "evidence_url": null,
      "api_item_ids": [],
      "validity": "reported",
      "upstream_status": "fix_proposed",
      "duplicate_of": null,
      "edit_version": 4
    }

Read and join the discussion on the report →