jshift 0.7.0

Schema-guided typed JSON on raw bytes: path get/mutate, open views, project — without a Value tree.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
//! Duplicate object-key policy (security / RFC grey area).
//!
//! JSON does not forbid repeated keys; parsers disagree on first-vs-last.
//! jshift path finds use **first match** by default (stable, cheap). This module
//! lets callers **resolve** or **reject** duplicates explicitly — no silent no-ops.
//!
//! # Efficiency
//!
//! Scans borrow **on-wire key content** from the input buffer (`&[u8]` into `json`).
//! No per-key `Vec` allocation in the hot path. Accumulators store only first/last
//! key quote offsets + value spans + a count. [`Error::DuplicateKey`] allocates a
//! display `String` only when rejecting.
//!
//! | API | Behavior |
//! | --- | --- |
//! | [`check_duplicate_keys`] + [`DuplicateKeyPolicy::First`]/ [`Last`](DuplicateKeyPolicy::Last) | [`ObjectKeyReport`]: every key once, winning value span, `has_duplicates` |
//! | [`check_duplicate_keys`] + [`DuplicateKeyPolicy::Error`] | `Err(DuplicateKey)` on first repeat; `Ok(report)` if all unique |
//! | [`validate_unique_keys`] / [`validate_unique_keys_deep`] | Security shorthand (Error only; deep uses a lighter unique-only scan) |
//!
//! ```
//! use jshift::{check_duplicate_keys, validate_unique_keys, DuplicateKeyPolicy};
//!
//! let bad = br#"{"a":1,"b":2,"a":3}"#;
//!
//! // Resolve: last write wins for "a"
//! let report = check_duplicate_keys(bad, DuplicateKeyPolicy::Last).unwrap();
//! assert!(report.has_duplicates);
//! let a = report.get("a").unwrap();
//! assert_eq!(&bad[a.value_start..a.value_end], b"3");
//! assert_eq!(a.occurrences, 2);
//! assert_eq!(a.first_key_pos, 1); // opening quote of first `"a"`
//!
//! // Reject
//! assert!(validate_unique_keys(bad).is_err());
//! assert!(check_duplicate_keys(bad, DuplicateKeyPolicy::Error).is_err());
//! ```

use std::collections::HashMap;

use crate::error::Error;
use crate::path::{try_parse_path, PathSegment};
use crate::scan::{find_string_end, find_value_offsets, skip_value, skip_whitespace};

/// How to treat repeated keys in a JSON object.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum DuplicateKeyPolicy {
    /// Keep the **first** occurrence’s value (matches jshift path-find default).
    ///
    /// Always returns [`ObjectKeyReport`] for a well-formed object (even with
    /// duplicates). Inspect [`ObjectKeyReport::has_duplicates`].
    #[default]
    First,
    /// Keep the **last** occurrence’s value (common in some JS engines).
    ///
    /// Always returns [`ObjectKeyReport`] for a well-formed object.
    Last,
    /// Fail with [`Error::DuplicateKey`] on the second occurrence of any key.
    ///
    /// On success, the report lists each unique key once (`has_duplicates == false`).
    /// `first_pos` / `pos` on the error are **opening-quote** offsets of the key
    /// strings (not value starts).
    Error,
}

/// Result of scanning one object’s members under a win policy.
///
/// Borrows on-wire key slices from the scanned document — keep `json` alive while
/// using the report.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ObjectKeyReport<'a> {
    /// One entry per distinct on-wire key, in first-seen order.
    pub keys: Vec<ResolvedObjectKey<'a>>,
    /// True if any key appeared more than once.
    pub has_duplicates: bool,
}

impl<'a> ObjectKeyReport<'a> {
    /// Look up by logical key name.
    ///
    /// Matches unescaped UTF-8 on-wire content (`"alice"` → `alice`). Escaped
    /// keys are only found if `key` equals the raw content between quotes.
    pub fn get(&self, key: &str) -> Option<&ResolvedObjectKey<'a>> {
        let kb = key.as_bytes();
        self.keys.iter().find(|k| k.key_raw == kb)
    }

    /// Winning value span for `key`, if present.
    pub fn value_span(&self, json: &'a [u8], key: &str) -> Option<&'a [u8]> {
        let r = self.get(key)?;
        Some(r.value(json))
    }
}

/// One logical key after applying First/Last (or unique Error success).
///
/// All offsets are absolute into the scanned document buffer.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ResolvedObjectKey<'a> {
    /// On-wire key content **between** quotes (borrowed; may contain escapes).
    pub key_raw: &'a [u8],
    /// Inclusive start of the winning value.
    pub value_start: usize,
    /// Exclusive end of the winning value.
    pub value_end: usize,
    /// How many times this key appeared.
    pub occurrences: u32,
    /// Byte offset of the **first** key’s opening `"` quote.
    pub first_key_pos: usize,
    /// Byte offset of the **last** key’s opening `"` quote.
    pub last_key_pos: usize,
}

impl<'a> ResolvedObjectKey<'a> {
    /// Winning value bytes in `json`.
    #[inline]
    pub fn value(&self, json: &'a [u8]) -> &'a [u8] {
        &json[self.value_start..self.value_end]
    }

    /// Key as `&str` when on-wire content is unescaped UTF-8.
    #[inline]
    pub fn key_str(&self) -> Option<&'a str> {
        if self.key_raw.contains(&b'\\') {
            return None;
        }
        std::str::from_utf8(self.key_raw).ok()
    }

    /// Lossy display form of the on-wire key content.
    #[inline]
    pub fn key_display(&self) -> std::borrow::Cow<'a, str> {
        String::from_utf8_lossy(self.key_raw)
    }

    #[inline]
    pub fn is_duplicate(&self) -> bool {
        self.occurrences > 1
    }
}

/// Per-key accumulator: first/last quote offsets + value spans + count only.
#[derive(Clone, Copy)]
struct KeyAcc {
    first_key_pos: usize,
    first_vs: usize,
    first_ve: usize,
    last_key_pos: usize,
    last_vs: usize,
    last_ve: usize,
    occurrences: u32,
}

/// Scan the root object: resolve wins (First/Last) or reject (Error).
#[inline]
pub fn check_duplicate_keys<'a>(
    json: &'a [u8],
    policy: DuplicateKeyPolicy,
) -> Result<ObjectKeyReport<'a>, Error> {
    check_duplicate_keys_at(json, &[], policy)
}

/// Scan the object at `path` (empty = root).
pub fn check_duplicate_keys_at<'a>(
    json: &'a [u8],
    path: &[PathSegment],
    policy: DuplicateKeyPolicy,
) -> Result<ObjectKeyReport<'a>, Error> {
    let (start, end) = object_range(json, path)?;
    scan_object_report(json, start, end, policy)
}

/// Path string helper (`""` = root).
pub fn check_duplicate_keys_path<'a>(
    json: &'a [u8],
    path: &str,
    policy: DuplicateKeyPolicy,
) -> Result<ObjectKeyReport<'a>, Error> {
    if path.is_empty() {
        check_duplicate_keys(json, policy)
    } else {
        let segs = try_parse_path(path)?;
        check_duplicate_keys_at(json, &segs, policy)
    }
}

/// Security shorthand: reject any duplicate key at the root object.
///
/// Uses a unique-only scan (no report built on success).
#[inline]
pub fn validate_unique_keys(json: &[u8]) -> Result<(), Error> {
    let (start, end) = object_range(json, &[])?;
    scan_object_unique_only(json, start, end)
}

/// Reject duplicates on the object at `path`.
#[inline]
pub fn validate_unique_keys_at(json: &[u8], path: &[PathSegment]) -> Result<(), Error> {
    let (start, end) = object_range(json, path)?;
    scan_object_unique_only(json, start, end)
}

/// Reject duplicates on the object at path string (`""` = root).
#[inline]
pub fn validate_unique_keys_path(json: &[u8], path: &str) -> Result<(), Error> {
    if path.is_empty() {
        validate_unique_keys(json)
    } else {
        let segs = try_parse_path(path)?;
        validate_unique_keys_at(json, &segs)
    }
}

/// Recursively reject duplicate keys in every nested object (unique-only, no reports).
pub fn validate_unique_keys_deep(json: &[u8]) -> Result<(), Error> {
    let start = skip_whitespace(json, 0);
    if start >= json.len() {
        return Err(Error::TypeMismatch {
            expected: "value",
            found: "eof",
        });
    }
    scan_value_unique(json, start)
}

/// Alias: deep scan with [`DuplicateKeyPolicy::Error`] only.
///
/// First/Last deep reports are not defined; use shallow [`check_duplicate_keys`]
/// per object for win reports.
#[inline]
pub fn check_duplicate_keys_deep(json: &[u8], policy: DuplicateKeyPolicy) -> Result<(), Error> {
    match policy {
        DuplicateKeyPolicy::Error => validate_unique_keys_deep(json),
        DuplicateKeyPolicy::First | DuplicateKeyPolicy::Last => Err(Error::InvalidPath {
            msg: "check_duplicate_keys_deep only supports DuplicateKeyPolicy::Error; use check_duplicate_keys per object for First/Last reports",
        }),
    }
}

/// Resolve which value span wins for one `key_raw` (on-wire content between quotes).
///
/// Single-pass over the object; does not build a full [`ObjectKeyReport`].
/// Under [`DuplicateKeyPolicy::Error`], returns [`Error::DuplicateKey`] if the
/// key appears more than once (`first_pos` / `pos` are opening-quote offsets).
pub fn object_key_wins<'a>(
    json: &'a [u8],
    object_start: usize,
    object_end: usize,
    key_raw: &[u8],
    policy: DuplicateKeyPolicy,
) -> Result<&'a [u8], Error> {
    let mut first: Option<(usize, usize, usize)> = None; // key_pos, vs, ve
    let mut last: Option<(usize, usize, usize)> = None;
    let mut pos = skip_whitespace(json, object_start + 1);
    while pos < object_end {
        pos = skip_whitespace(json, pos);
        if pos >= object_end || json[pos] == b'}' {
            break;
        }
        if json[pos] != b'"' {
            return Err(Error::InvalidJsonSyntax {
                pos,
                msg: "Expected object key string",
            });
        }
        let key_pos = pos;
        let ks = pos + 1;
        let ke = find_string_end(json, ks)?;
        let this_key = &json[ks..ke];
        pos = skip_whitespace(json, ke + 1);
        if pos >= object_end || json[pos] != b':' {
            return Err(Error::InvalidJsonSyntax {
                pos,
                msg: "Expected colon after object key",
            });
        }
        pos = skip_whitespace(json, pos + 1);
        let vs = pos;
        let ve = skip_value(json, vs)?;
        if this_key == key_raw {
            if let Some((first_kp, _, _)) = first {
                if policy == DuplicateKeyPolicy::Error {
                    return Err(Error::DuplicateKey {
                        key: String::from_utf8_lossy(key_raw).into_owned(),
                        first_pos: first_kp,
                        pos: key_pos,
                    });
                }
            } else {
                first = Some((key_pos, vs, ve));
            }
            last = Some((key_pos, vs, ve));
        }
        pos = skip_whitespace(json, ve);
        if pos < object_end && json[pos] == b',' {
            pos += 1;
        }
    }
    let win = match policy {
        DuplicateKeyPolicy::First | DuplicateKeyPolicy::Error => first,
        DuplicateKeyPolicy::Last => last.or(first),
    };
    let (_kp, vs, ve) = win.ok_or(Error::PathNotFound)?;
    Ok(&json[vs..ve])
}

fn object_range(json: &[u8], path: &[PathSegment]) -> Result<(usize, usize), Error> {
    if path.is_empty() {
        let s = skip_whitespace(json, 0);
        if s >= json.len() || json[s] != b'{' {
            return Err(Error::TypeMismatch {
                expected: "object",
                found: "non-object",
            });
        }
        let e = skip_value(json, s)?;
        Ok((s, e))
    } else {
        let (s, e) = find_value_offsets(json, path)?;
        if s >= json.len() || json[s] != b'{' {
            return Err(Error::TypeMismatch {
                expected: "object",
                found: "non-object",
            });
        }
        Ok((s, e))
    }
}

/// Full report: borrow keys, O(1) extra state per distinct key (first/last only).
fn scan_object_report<'a>(
    json: &'a [u8],
    start: usize,
    end: usize,
    policy: DuplicateKeyPolicy,
) -> Result<ObjectKeyReport<'a>, Error> {
    let mut order: Vec<&'a [u8]> = Vec::new();
    let mut map: HashMap<&'a [u8], KeyAcc> = HashMap::new();

    let mut pos = skip_whitespace(json, start + 1);
    while pos < end {
        pos = skip_whitespace(json, pos);
        if pos >= end || json[pos] == b'}' {
            break;
        }
        if json[pos] != b'"' {
            return Err(Error::InvalidJsonSyntax {
                pos,
                msg: "Expected object key string",
            });
        }
        let key_pos = pos;
        let ks = pos + 1;
        let ke = find_string_end(json, ks)?;
        let key_raw = &json[ks..ke];
        pos = skip_whitespace(json, ke + 1);
        if pos >= end || json[pos] != b':' {
            return Err(Error::InvalidJsonSyntax {
                pos,
                msg: "Expected colon after object key",
            });
        }
        pos = skip_whitespace(json, pos + 1);
        let vs = pos;
        let ve = skip_value(json, vs)?;

        match map.get_mut(key_raw) {
            Some(acc) => {
                if policy == DuplicateKeyPolicy::Error {
                    return Err(Error::DuplicateKey {
                        key: String::from_utf8_lossy(key_raw).into_owned(),
                        first_pos: acc.first_key_pos,
                        pos: key_pos,
                    });
                }
                acc.occurrences += 1;
                acc.last_key_pos = key_pos;
                acc.last_vs = vs;
                acc.last_ve = ve;
            }
            None => {
                order.push(key_raw);
                map.insert(
                    key_raw,
                    KeyAcc {
                        first_key_pos: key_pos,
                        first_vs: vs,
                        first_ve: ve,
                        last_key_pos: key_pos,
                        last_vs: vs,
                        last_ve: ve,
                        occurrences: 1,
                    },
                );
            }
        }

        pos = skip_whitespace(json, ve);
        if pos < end && json[pos] == b',' {
            pos += 1;
        }
    }

    let mut has_duplicates = false;
    let mut keys = Vec::with_capacity(order.len());
    for key_raw in order {
        let acc = map.remove(key_raw).expect("key in order");
        if acc.occurrences > 1 {
            has_duplicates = true;
        }
        let (vs, ve) = match policy {
            DuplicateKeyPolicy::First | DuplicateKeyPolicy::Error => (acc.first_vs, acc.first_ve),
            DuplicateKeyPolicy::Last => (acc.last_vs, acc.last_ve),
        };
        keys.push(ResolvedObjectKey {
            key_raw,
            value_start: vs,
            value_end: ve,
            occurrences: acc.occurrences,
            first_key_pos: acc.first_key_pos,
            last_key_pos: acc.last_key_pos,
        });
    }

    Ok(ObjectKeyReport {
        keys,
        has_duplicates,
    })
}

/// Unique-only: map key_raw → first opening-quote pos. No report, no value storage.
fn scan_object_unique_only(json: &[u8], start: usize, end: usize) -> Result<(), Error> {
    let mut seen: HashMap<&[u8], usize> = HashMap::new();
    let mut pos = skip_whitespace(json, start + 1);
    while pos < end {
        pos = skip_whitespace(json, pos);
        if pos >= end || json[pos] == b'}' {
            break;
        }
        if json[pos] != b'"' {
            return Err(Error::InvalidJsonSyntax {
                pos,
                msg: "Expected object key string",
            });
        }
        let key_pos = pos;
        let ks = pos + 1;
        let ke = find_string_end(json, ks)?;
        let key_raw = &json[ks..ke];
        pos = skip_whitespace(json, ke + 1);
        if pos >= end || json[pos] != b':' {
            return Err(Error::InvalidJsonSyntax {
                pos,
                msg: "Expected colon after object key",
            });
        }
        pos = skip_whitespace(json, pos + 1);
        let vs = pos;
        let ve = skip_value(json, vs)?;

        if let Some(&first_pos) = seen.get(key_raw) {
            return Err(Error::DuplicateKey {
                key: String::from_utf8_lossy(key_raw).into_owned(),
                first_pos,
                pos: key_pos,
            });
        }
        seen.insert(key_raw, key_pos);

        pos = skip_whitespace(json, ve);
        if pos < end && json[pos] == b',' {
            pos += 1;
        }
    }
    Ok(())
}

fn scan_value_unique(json: &[u8], start: usize) -> Result<(), Error> {
    let start = skip_whitespace(json, start);
    if start >= json.len() {
        return Ok(());
    }
    match json[start] {
        b'{' => {
            let end = skip_value(json, start)?;
            scan_object_unique_only(json, start, end)?;
            let mut pos = skip_whitespace(json, start + 1);
            while pos < end {
                pos = skip_whitespace(json, pos);
                if pos >= end || json[pos] == b'}' {
                    break;
                }
                if json[pos] != b'"' {
                    return Err(Error::InvalidJsonSyntax {
                        pos,
                        msg: "Expected object key string",
                    });
                }
                let ks = pos + 1;
                let ke = find_string_end(json, ks)?;
                pos = skip_whitespace(json, ke + 1);
                if pos >= end || json[pos] != b':' {
                    return Err(Error::InvalidJsonSyntax {
                        pos,
                        msg: "Expected colon after object key",
                    });
                }
                pos = skip_whitespace(json, pos + 1);
                let vs = pos;
                let ve = skip_value(json, vs)?;
                scan_value_unique(json, vs)?;
                pos = skip_whitespace(json, ve);
                if pos < end && json[pos] == b',' {
                    pos += 1;
                }
            }
            Ok(())
        }
        b'[' => {
            let end = skip_value(json, start)?;
            let mut pos = skip_whitespace(json, start + 1);
            while pos < end {
                pos = skip_whitespace(json, pos);
                if pos >= end || json[pos] == b']' {
                    break;
                }
                let ve = skip_value(json, pos)?;
                scan_value_unique(json, pos)?;
                pos = skip_whitespace(json, ve);
                if pos < end && json[pos] == b',' {
                    pos += 1;
                }
            }
            Ok(())
        }
        _ => Ok(()),
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn error_rejects_duplicate_key_quote_offsets() {
        // {"a":1,"b":2,"a":3}
        //  0123456789...
        // `{"a":1,"b":2,"a":3}` — first `"a"` opens at 1; second at 13
        let j = br#"{"a":1,"b":2,"a":3}"#;
        let e = check_duplicate_keys(j, DuplicateKeyPolicy::Error).unwrap_err();
        match e {
            Error::DuplicateKey {
                first_pos,
                pos,
                key,
            } => {
                assert_eq!(key, "a");
                assert_eq!(first_pos, 1);
                assert_eq!(j[first_pos], b'"');
                assert_eq!(pos, 13);
                assert_eq!(j[pos], b'"');
            }
            other => panic!("unexpected {other:?}"),
        }
        validate_unique_keys(j).unwrap_err();
    }

    #[test]
    fn first_and_last_report_wins_zero_key_alloc_path() {
        let j = br#"{"a":1,"b":2,"a":3}"#;
        let first = check_duplicate_keys(j, DuplicateKeyPolicy::First).unwrap();
        assert!(first.has_duplicates);
        assert_eq!(first.value_span(j, "a").unwrap(), b"1");
        assert_eq!(first.get("a").unwrap().occurrences, 2);
        assert_eq!(first.get("a").unwrap().first_key_pos, 1);
        assert_eq!(first.get("a").unwrap().last_key_pos, 13);
        // borrowed key_raw points into j
        let a = first.get("a").unwrap();
        assert_eq!(a.key_raw.as_ptr(), j[2..3].as_ptr());

        let last = check_duplicate_keys(j, DuplicateKeyPolicy::Last).unwrap();
        assert_eq!(last.value_span(j, "a").unwrap(), b"3");
        assert_eq!(last.get("b").unwrap().value(j), b"2");
    }

    #[test]
    fn unique_error_ok_report() {
        let j = br#"{"a":1,"b":2}"#;
        let r = check_duplicate_keys(j, DuplicateKeyPolicy::Error).unwrap();
        assert!(!r.has_duplicates);
        assert_eq!(r.keys.len(), 2);
        validate_unique_keys(j).unwrap();
    }

    #[test]
    fn deep_unique() {
        assert!(validate_unique_keys_deep(br#"{"ok":{"x":1},"bad":{"y":1,"y":2}}"#).is_err());
        validate_unique_keys_deep(br#"{"ok":{"x":1},"good":{"y":1,"z":2}}"#).unwrap();
    }

    #[test]
    fn deep_first_last_rejected() {
        assert!(matches!(
            check_duplicate_keys_deep(br#"{}"#, DuplicateKeyPolicy::First),
            Err(Error::InvalidPath { .. })
        ));
    }

    #[test]
    fn object_key_wins_single_pass() {
        let j = br#"{"a":1,"a":2}"#;
        assert_eq!(
            object_key_wins(j, 0, j.len(), b"a", DuplicateKeyPolicy::First).unwrap(),
            b"1"
        );
        assert_eq!(
            object_key_wins(j, 0, j.len(), b"a", DuplicateKeyPolicy::Last).unwrap(),
            b"2"
        );
        let e = object_key_wins(j, 0, j.len(), b"a", DuplicateKeyPolicy::Error).unwrap_err();
        match e {
            Error::DuplicateKey {
                first_pos, pos, ..
            } => {
                assert_eq!(j[first_pos], b'"');
                assert_eq!(j[pos], b'"');
                assert!(pos > first_pos);
            }
            other => panic!("{other:?}"),
        }
    }
}