/** * Non-backtracking wildcard matchers for DQL `LIKE` and path globs. * * v3.10.0-rc.71 (post-rc.66 re-sweep, ReDoS class — closes the rc.63/rc.68 siblings): * both DQL `LIKE` ({@link compileLike}) and path globs ({@link compileGlob}) used to * compile the pattern into a backtracking `RegExp`. A pattern with unbounded wildcards * SEPARATED BY LITERALS (`*a*a*…` for LIKE, `**a**a**…` for glob) — which neither the * rc.63 run-collapse nor the rc.68 adjacency-collapse touched — produces `^.*a.*a…$`, * the textbook catastrophic shape: against a NON-matching subject the engine tries * every partition of the subject across the wildcards (≈ C(len, k) backtracks), * measured at **110 s** for `.*a`×14 against a 41-char subject via the always-on, * bearer-reachable `obsidian_dataview_query`. The catastrophe scales with the SUBJECT * length, so a wildcard COUNT cap is NOT structurally safe (a long path / field value * blows up at a handful of wildcards, and a count-cap also rejects legitimate * patterns). Per the rc.39 lesson — *bound the SINK, don't chase shapes* — the durable * fix is to not use a backtracking regex at all: a tabular DP over (token, position) * that is **O(tokens × len) for every input**, so no pattern can exceed a linear * budget. The atomic-group emulation `(?=(.*))\1` was rejected (empirically: it stops * backtracking but CHANGES matching semantics — it can't yield chars back to a * required following literal). */ /** A single token of a compiled wildcard pattern. */ export type WildcardToken = { lit: string; } | { kind: "any"; } | { kind: "segstar"; } | { kind: "question"; }; export interface MatchOpts { /** Fold case before comparing literals (LIKE is case-insensitive; glob is not). */ caseInsensitive?: boolean; } /** * Match `value` against a compiled token list in O(tokens × value.length) time with * NO backtracking. Bottom-up DP with two rolling rows: `next[vi]` = "can the token * suffix starting at the next token match `value[vi..]`"; `cur[vi]` = the same for the * current token. Iterating `vi` descending lets the `any`/`segstar` self-recurrence * (`cur[vi+1]`) read an already-filled cell — that recurrence is what makes a wildcard * linear instead of a regex backtrack. * * v3.10.0-rc.75 — CASE-FOLD CONTRACT (accepted divergence from the pre-rc.71 regex; the * post-rc.74 re-sweep's one LOW finding): when `caseInsensitive` is set (DQL `LIKE` only), * folding is `String.prototype.toLowerCase()`, NOT the ECMAScript `RegExp` `i`+`u` canonical * case-folding the pre-rc.71 `^…$/iu` regex used. These agree for ASCII + ordinary accented * letters but DIVERGE for ~22 exotic BMP codepoints whose `i`-flag canonical fold differs from * `toLowerCase` — e.g. micro-sign `µ` (U+00B5) vs Greek mu `Μ`, long-s `ſ` (U+017F) vs `S`, * final-sigma `ς` (U+03C2) vs `Σ`, the Greek symbol variants `ϐϑϕϖϰϱϵ`, the U+1C80–U+1C88 * Cyrillic small-caps block, `ẛ` (U+1E9B), `ι` (U+1FBE). For these, `field LIKE "µ"` no longer * matches a value of `"Μ"` (direction is UNDER-match — fewer rows, never over-exposure). This is * a deliberate, accepted trade-off: those characters are vanishingly rare in real vaults, and a * custom Unicode-canonical folder is its own bug surface; it is pinned by the case-fold-contract * test in `tests/wildcard-match.test.ts` (which also proves the divergence is real via a * NEGATIVE control against the old regex). The glob path ({@link compileGlob}) is case-SENSITIVE * and never folds, so the privacy filter is byte-faithful to the pre-rc.71 behavior. */ export declare function matchWildcardTokens(tokens: readonly WildcardToken[], value: string, opts?: MatchOpts): boolean; /** * Tokenize a DQL `LIKE` pattern. `*` is the only wildcard (any run of chars); * `\x` escapes the next char to a literal (so `\*` is a literal asterisk, `\\` a * literal backslash); a trailing `\` is a literal backslash. Consecutive `*` coalesce * into one `any` token (semantically identical, keeps the token list small). The * escape semantics are byte-for-byte the pre-rc.71 `likeToRegex` rules — only * the final consumer changed (a linear matcher instead of `new RegExp`). */ export declare function compileLikeTokens(pattern: string): WildcardToken[]; /** * Tokenize a minimal glob into wildcard tokens, mirroring the pre-rc.71 * `globToRegex` grammar exactly (so matching semantics are preserved): * `**` — globstar, any run of chars INCLUDING `/`; consumes the rest of the `*` * run and ONE trailing `/` (so `a/**​/b` matches `a/b`) → `any` * `*` — any run of NON-`/` chars → `segstar` * `?` — exactly one NON-`/` char → `question` * else — literal char (no regex escaping needed — the matcher compares chars directly) * No bracket sets / `!` / `{a,b}`. The match is full-path anchored (the DP requires the * whole token list to consume the whole path), matching the old `^…$` regex. */ export declare function compileGlobTokens(glob: string): WildcardToken[]; /** Strip the trailing run of chars satisfying `pred` — O(n), no backtracking. */ export declare function stripTrailingRun(s: string, pred: (code: number) => boolean): string; /** Strip the leading run of chars satisfying `pred` — O(n), no backtracking. */ export declare function stripLeadingRun(s: string, pred: (code: number) => boolean): string; /** `s.replace(/\/+$/, "")` — linear. */ export declare function stripTrailingSlashes(s: string): string; /** `s.replace(/^\/+|\/+$/g, "")` — linear (leading AND trailing slash runs). */ export declare function stripSurroundingSlashes(s: string): string; /** `s.replace(/\n+$/, "")` — linear. */ export declare function stripTrailingNewlines(s: string): string; /** `s.replace(/#+$/, "")` — linear (ATX heading closing hashes). */ export declare function stripTrailingHashes(s: string): string; /** * Strip the trailing run of JS line-terminator chars (`\n` `\r` U+2028 U+2029) — linear. * * v3.11.0-rc.17 (rc.16 re-audit, CRLF heading-drop regression) — a line obtained * from `body.split("\n")` retains a trailing `\r` on a CRLF (Windows) note, and * ` `/` ` are never split on at all. The rc.16 heading capture * `/^(#{1,6})\s+(.+)$/` then MATCHES NOTHING, because JS `.` (no `s` flag) does * not match a line terminator and `$` (no `m` flag) only matches true end-of-input * — so the trailing `\r` makes `(.+)$` fail and the heading is silently dropped. * The pre-rc.16 combined form absorbed the `\r` via its trailing `\s*`. Strip the * terminator (linearly — a `replace(/[\r\n…]+$/,"")` would itself be the * polynomial-ReDoS class the static guard polices) before the heading match. */ export declare function stripTrailingLineEnds(s: string): string; export declare function splitLines(text: string): string[]; /** * Split `text` into lines AND the exact terminator that followed each line. * `lines[i]` is the line text (terminator-stripped, identical to {@link splitLines}); * `ends[i]` is the terminator that followed it (`""` for the final line when the text * has no trailing terminator). Rejoin faithfully with * `lines.map((l, i) => l + ends[i]).join("")` \u2014 this PRESERVES CRLF / CR / U+2028 / * U+2029 line endings on every line, including untouched ones. * * v3.11.4-rc.2 \u2014 the write-path rewriters (`rewriteOutsideCodeFences` / * `replaceStringOutsideCodeFences`) split with the terminator-aware {@link splitLines} * (rc.23) but rejoined with a hard-coded `"\n"`, silently flattening a whole CRLF * (Windows) note to LF on any `replace_in_notes` / `rename_note` edit. Splitting on a * CAPTURING terminator group keeps each line's own ending so the rejoin is byte-faithful. */ export declare function splitLinesWithEnds(text: string): { lines: string[]; ends: string[]; }; /** * Count the line BREAKS in `text` per the {@link splitLines} terminator set * (LF / CRLF / CR / U+2028 / U+2029) \u2014 i.e. `splitLines(text).length - 1`. * * v3.11.0-rc.25 (post-rc.24 pre-promotion re-sweep) \u2014 the COUNTING sibling of the rc.23 * split class. Line-NUMBER math that used `(text.match(/\n/g) ?? []).length` counts only LF, * so on a bare-CR / U+2028 / U+2029 note the reported `line_start`/`line_end` (chatThreadAppend) * and breadcrumb line numbers (fts5) drifted \u2014 the same blindness `splitLines` fixed for the * splitting form. The rc.23 inventory invariant only patrolled `.split("\n")`; it now also * flags `.match(/\n/g)`, and these counters route through here. */ export declare function countLineBreaks(text: string): number; /** * Case-fold a string for case-INSENSITIVE substring matching by lower-casing each * Unicode CODE POINT independently (context-free). Use this for BOTH the needle AND * the haystack of any case-insensitive search — NEVER whole-string * `String.prototype.toLowerCase()` on one side and a per-code-point fold on the other. * * Whole-string `.toLowerCase()` applies CONTEXT-SENSITIVE rules — most notably Greek * word-final sigma: `"ΟΔΟΣ".toLowerCase()` → `"οδος"` (final `ς`), whereas a * per-code-point fold yields `"οδοσ"` (medial `σ`, no context). So a whole-string-folded * needle (`"οδος"`) silently FAILS to match a per-code-point-folded haystack (`"…οδοσ…"`) * → a SILENT miss. That is exactly what bit `replace_in_notes` (the needle was * `search.toLowerCase()` while the line was folded per code unit → a case-insensitive * Greek replace ending in a capital Σ reported 0 replacements) and is the same hazard the * read-path `foldWithMap` (search.ts) avoids by folding the haystack per code point. * * v3.11.1-rc.1 (v3.11.0 STABLE external audit — anti-anchoring finding) — the fold sibling * of the rc.18/rc.21/rc.46 case-fold-asymmetry class. Iterates by code point (`for..of`), * so astral case-folding chars (e.g. Deseret `𐐀`→`𐐨`) fold correctly too — a per-UTF-16-unit * `charAt` loop would split the surrogate pair and leave them UNfolded, re-introducing the * very asymmetry on the astral plane. */ export declare function foldForMatch(s: string): string; //# sourceMappingURL=wildcard-match.d.ts.map