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
//! Root confinement for catalog resolution.
//!
//! Every file the catalog serves is named relative to the prompts directory,
//! so a pattern or a `[prompts.NAME].file` that reaches outside it is a
//! configuration mistake, not a prompt. Two checks enforce that:
//!
//! - the shape check [`crate::relpath::reject_traversal`] refuses a pattern or
//! path whose components could climb out of the root; it runs at the
//! configuration boundary, so a value that reaches resolution is already
//! known to be relative.
//! - [`confined`] refuses a resolved file whose canonical location is not a
//! descendant of the canonical root, which is what catches a symlink or
//! reparse point placed under the root that points outside it - an escape no
//! shape check can see.
use Path;
/// Whether `file` resolves to a location inside the prompts directory.
///
/// Both the root and the file are canonicalized, so a symlink under the root
/// that points outside it resolves to its target and is refused. A file that
/// cannot be canonicalized (it was removed mid-pass, or the root does not
/// exist) is treated as not confined rather than admitted on faith.
pub
/// Whether `a` and `b` name the same file by canonical identity rather than
/// lexical spelling.
///
/// This is what lets a `[prompts.NAME]` block spelled `./top.md` recognize the
/// globbed `top.md` as the file it overrides, and a block naming a symlink
/// recognize the target a glob already matched, so the block replaces that
/// entry rather than adding a second that then collides on name. A path that
/// cannot be canonicalized falls back to lexical equality, which errs toward
/// treating the paths as distinct rather than overwriting on an unproven match.
pub