You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Patterns: regex triggers (B-074, ADR-0008). The new Patterns page (Settings; a page on Obsidian 1.13+, its own tab below it) lists the rules and lets you add, edit, turn off, reorder (drag the handle, Alt+Up and Alt+Down, or the menu) and delete them. The pattern is checked as you type, with a sentence under the field for every refusal and Save disabled until it passes; a Try it field replays a typed line through the real engine and says what fires, which rule or snippet fires first, and when an instant rule fires too early (1/23 gives ½3); rules the guard turned off for the session show as Paused, and an instant rule while Expand while typing is off says it will not fire. The typography set adds 32 rules (fractions after a separator, arrows, ≠, ≤, ≥, ±, … and more, from the Substitutions defaults) in one click. settings.patterns holds rules written as /pattern$/flags (the flag i only, as written) with a replacement that can use {{0}} (whole match), {{1}}..{{9}} and {{name}} for named groups, next to $|, $1..$9 fields, $date, $clipboard. Captured text is inserted last and literally, so a captured $1, $| or {{date}} stays text and field and caret positions account for it. Each rule is instant (tried after every typed character, the match must end at the caret) or separator (tried like a literal trigger, on a separator or on "Expand trigger at cursor"). Literal triggers win over every pattern. Separator rules also run on Tab ("Expand on Tab") and on the Text Snippets alias command, after a literal trigger: with the caret inside a word the rule reads the line up to the end of the word and counts only if its match starts at or before the caret (a match that lies wholly after it is left alone, the rules further down are then not tried either because the first matching rule owns the word, and Tab passes through); instant rules never run there, and with "Expand while typing" off they stop running as you type too. Patterns are then tried strictly top to bottom whatever their mode, the first match wins: a separator rule reads the line before the typed separator, an instant rule the line through it. Patterns also run when the literal lookup came back empty (:(\w+):$ fires on the space after the closing colon), prefix mode does not apply to them, only the last 64 characters of the line are looked at (plus 16 characters of context so \b and lookbehind do not see a false line start), the match must end at the caret, and code, math, frontmatter and non-typing edits are skipped as for any trigger. A pattern expansion is its own undo step (Cmd/Ctrl+Z gives back what was typed) and works with Highlight + Backspace in both modes. Rules in a disabled group are skipped. With Obsidian's auto-pairing on ("Auto-pair brackets": brackets and quotes; "Auto-pair Markdown syntax": *, _ and backtick), an instant rule ending in a paired character (/\(c\)$/i, /\*x\*$/) fires when the closing character is typed, although the editor only steps the caret over the closer it inserted: only a closer the editor just auto-inserted counts (an arrow key or a click onto another ) does not), a typo fixed with Backspace inside the pair does not lose it, and literal snippets and separator rules are not tried on that step. A rule that ends in the opener (/:\($/ to a sad face) runs as the pair is inserted and takes the auto-inserted closer with it in the same undo step, so the text is what the same typing gives with auto-pairing off and one Undo, or Backspace with Highlight on, brings back the pair with the caret inside. A rule written without an id (a hand edit or sync) shows as an error and is kept off, also when it is saved from the editor, until you turn it on. Saved data from this version survives a round trip through 1.8.0.
Espanso import: regex: matches become pattern rules (B-074, ADR-0008). The import on the Packages page used to skip every regex: match; now each one is converted and listed in the preview as its own Pattern rules section (pattern, replacement, mode, or the reason it was left out), and Apply writes the snippets and the rules together with one save (a failed save puts both back; the rules go to the end of the list, switched on, in the group named in the import). The conversion: (?P<name> becomes (?<name>; {{name}} in the replacement is the capture of the same name (Espanso has named groups only; a {{1}} or a name that is no group of the regex is refused, because here it would mean a numbered capture or stay literal text); the closing $ is appended when the regex does not end with an unescaped one (\$ is a dollar sign); a leading (?i) becomes the flag i. The rule is imported as Instant, as Espanso fires it, and as After a separator (with a note in the preview) when only the instant limit of one open-ended repeat stops it, as with (\d+)/(\d+). Left out, each with a reason: any other inline flag, Rust class syntax that JavaScript reads differently ([[:alpha:]], nested classes, &&, --, ~~), \p{...}, backreferences, lookahead, nested quantifiers and everything else the Patterns page refuses (with the sentence it shows), a replacement with vars:, a form, a shell, script or choice variable, case propagation, an image, and word, left_word or right_word (a pattern cannot honour them exactly). \w, \d, \b and their negations are Unicode-aware in Espanso and ASCII-based in a pattern, so an imported rule can match differently on text with non-ASCII letters; a leading (?i) folds case the simple way here and the Unicode way in Espanso (rare letters such as ſ and the Kelvin sign differ); and ^ means the start of the line here, the start of Espanso's buffer there. {{ name }} with spaces, {{name.sub}} and any other {{...}} that is not exactly {{name}} of a named group is left out; {{ clipboard }} with spaces now maps to $clipboard like {{clipboard}}, for plain triggers too. A rule with the same pattern and replacement as one you already have is left out as "already there", and rules past the 100 rule limit as "over the 100 rule limit". What an import inserts is what Espanso inserts, or the match is left out with a reason (B-266), for plain triggers and regex matches alike. Text that is plain in Espanso but live syntax here is no longer changed silently: $1 to $9 in the replacement (costs $5, pay $1 on) are stored with the escape \$5 and insert as written (they used to become fields or vanish); plain $|, $date, $time, $filename, $clipboard, {{date}}, {{time}}, {{date:FMT}} and {{time:FMT}} have no escape, so a match that contains one is left out; a \$1 already written with a backslash is left out too, because here the backslash would be eaten. {{clipboard}} or a date variable directly before a letter, digit or _ ({{d}}{{d}}a), or {{clipboard}} directly before a date or time variable ({{clipboard}}{{d}}), would become dead text, so the match is left out ({{d}}{{d}} alone imports as $date$date; {{date}} / {{time}} would end the token, but they render locale digits in some Obsidian languages where Espanso gives ASCII). A lone vars: entry of type clipboard is mapped like {{clipboard}} (plain triggers only), and so is a lone date variable whose only parameter is format (%Y-%m-%d or %H:%M); a date variable with offset, tz or locale is left out (any other parameter is ignored, as Espanso ignores it), and so is one whose name is not a word (empty, my-var, a.b, a²), because Espanso never reads that as a reference; a word is as in Espanso: letters and other alphabetic characters, marks, decimal digits, connector punctuation such as _, and joiners, with Unicode whitespace allowed inside the braces. Any other {{name}} or {{name.sub}} in a plain trigger's replacement is a variable in Espanso, never text (a missing one is an error there, a global_vars: one is a value Snipsy does not read), so the match is left out with uses {{name}}, a variable this match does not declare; on a regex match such a name is a capture group and is checked by the pattern conversion. An undeclared {{clipboard}} still maps to $clipboard: that is a Snipsy convenience, not something Espanso does. \{\{ and \}\} in a replacement are left out (Espanso turns them into plain braces). Espanso's $|$ cursor maps to $|; Espanso removes every $|$ and puts the cursor at the first, so only the first is kept. The reason for a left-out {{date:{{clipboard}}}} quotes the text as written. A pasted Espanso YAML over 2 MiB (the size limit of a package install) is refused with a message before it is parsed.
JSON backup includes pattern rules (B-074, ADR-0008). Export JSON in General now also writes your pattern rules, exactly as stored (unknown fields included), and Import JSON previews and applies them: a Pattern rules section lists the rules that will be stored, and the ones left out, each with the sentence the Patterns page shows. Merge appends the rules you do not have yet (same pattern and replacement) after yours and leaves yours untouched; Replace all swaps the whole rule list too, and the Replace hint says how many rules it deletes. A file without rules behaves as before and never touches your rules, and a stored patterns value that is not a list is never overwritten. Every rule goes through the same pattern check as the editor (S-015) and the 100 rule limit, again when you press Apply, with one save for snippets and rules together (a failed save puts both back); a rule without an id is stored switched off. At most 500 entries of a file are looked at, so a hostile file cannot freeze the preview. Older Snipsy versions read the backup as a flat object of strings and refuse a file with an array in it, so the rules travel as one more string entry named snipsy patterns (the rule list as JSON text): 1.7.0 and later list it as a skipped key and import everything else, older ones store it as a snippet that can never fire. A hand-written top-level patterns array is read too; if a file has both, the snipsy patterns entry wins, and a leftover snipsy patterns snippet is never exported as a snippet. The Backup rows and the Patterns page now say so.
A support link in the plugin's listing (fundingUrl in manifest.json), pointing at Buy Me a Coffee, as Dashy and Garmy have.
Security
S-015: ReDoS guard for patterns, in two parts. A JS regex cannot be interrupted, and a static check over its syntax can stop exponential backtracking but cannot bound polynomial cost (a lookbehind checked at every backtrack step, case folding under i), so the guarantees are split. 1. A static gate against exponential backtracking and against the parser disagreeing with the engine. Every rule goes through one function that checks the pattern with a small parser (not a regex over the regex) before it is compiled, whichever way it got into data.json (editor, import, sync, hand edit), and a rule that fails is disabled alone with its reason. Refused: a missing trailing $, backreferences, lookahead, a lookbehind with a quantifier or with more than 8 characters or groups in all its lookbehinds together, a repeated group whose body has a quantifier or an alternation ((a+)+, (a|aa)*), more than 2 unbounded quantifiers (1 for an instant rule, which runs after every keystroke: the reason says to switch the rule to "After a separator"), too many overlapping optional, ranged or alternating parts (?, {n,m}, (a|b)) next to them (a? x16, (?:a|) x30 or \w{0,10} x5 take 20 ms to minutes), a pattern that can match the empty string, the group names date, time, title and notedate (also when written with escapes: a backslash in a group name is refused), a body over 200 characters, a replacement over 10 000 characters, and more than 100 rules. Unicode property escapes are refused: every \p{...} and \P{...}, in or out of a class, under any flags, with "Unicode property classes like \p{L} aren't supported yet. Use \w or a range such as [а-яё]." V8 compiles one on the first non-Latin-1 exec, during typing, and a count cannot bound it: a single \p{L}{1,4} next to a short tail (\p{L}{1,4}-\d{2}-\d{2}$) took 90-430 ms, depending non-monotonically on the quantifier, the tail and the property. A malformed one (\pL, [\p], \p{RGI_Emoji}) gets the same hint. The u flag is refused; i is the only flag (owner, round 7): under u, V8 compiles adjacent short ranged terms slowly (the checker measured ~38 ms per exec for \S{1,4} x5 plus a tail, and 8.6 s over 100 keystrokes for 100 distinct such rules, none switched off), and only under u. The editor says "Flag u isn't allowed. Use i or none." Without u an emoji is two code units, so an emoji written as plain text (/:smile:$/, /😀x$/) works, and an emoji or any character outside the basic plane inside a class [...] is refused: "Emoji can't go inside [ ] yet. Write them as plain text, or use a group like (?:😀|🙏)." ([^😀] would match each half alone). A match never splits an emoji, and no capture holds half of one (round 8): a match that would start on the low half of a pair is dropped (/(.)x$/ on an emoji followed by x), so is one with a capture the replacement uses that begins with a low half or ends with a high half (/(.)(.)x$/ with {{1}}: without u, ., \S, \W and [^a] take one code unit), a line that ends between the halves of a pair is not matched until the pair is whole, a replacement that itself holds half of an emoji (a hand-edited data.json) is refused when the rule is compiled, and a last check refuses any expansion whose insert holds a lone half or would leave one at the edge of the replaced range. A quantifier right after an emoji (😀+, a😀?b, 😀{2}) is refused, because it would repeat only the low half: "A repeat can't follow an emoji directly. Put the emoji in a group, like (?:😀)+." A repeated group of emoji alternatives ((?:😀|🙏)+) is refused with a hint that does not point at [ ] (which refuses emoji), and an escaped emoji (\😀, which is a backslash before half of it), in or out of a class, is refused. Escapes are an allowlist: only \d \w \s and \b with their negations \D \W \S \B, \n \r \t \f \v, \0 (not before a digit), complete \xHH and \uHHHH (not a surrogate), and escaped symbols are read; legacy octal (\041), \c, an incomplete \x or \u and escaped letters are refused with "The escape \041 isn't supported. Write the character itself, or use \d, \w, \s or \b." (the escape as written), because the engine reads them differently from how they look. The matcher keeps 16 characters of context before its 64-character window, so a lookbehind sees all it needs and a cut line never looks like a line start, and the window never starts inside a surrogate pair. An instant rule is also skipped, without running its regex, unless the typed character (the last code unit) can end a match. 2. A runtime guard for polynomial cost, on the typing path only: each pattern match is timed. A slow sample is run again on the same text (up to 2 more times), because V8 compiles a regex lazily and the first runs of a rule can take a few ms, and only counts if the fastest run is still over 2 ms. Measured without u (Node, fresh process per run, Cyrillic and emoji text): the first exec of 288 accepted shapes made of adjacent short ranged terms (\S{1,4} x5 plus a tail and the like, with and without i) took 12 ms at worst, and 100 distinct rules of the \S{1,4} x5 shape after a separator cost 727 ms over 100 keystrokes, each keystroke held to the 8 ms budget, none switched off. A rule whose first, second or third exec costs more than 50 ms in all (the sum of that run's samples, re-runs included, so two samples of 43.7 and 48.9 ms count as 92.6) is switched off at once, whatever the cause (the page says "Turned off for this session: it took too long to compile."; the console warning says "Switched off: too expensive to compile (N ms)."). V8 compiles on the first runs and again when the string representation of the input changes, which the text alone cannot predict, so cold is decided by the run count only; a later spike on a warm rule, such as a GC pause, never counts. A rule with such a slow keystroke 3 times within its last 50 runs is switched off until the rules change or Obsidian restarts (the page says "Turned off for this session: it was too slow."; the reason is kept in memory, nothing is written to data.json, and one warning goes to the console, "Switched off: slow on this note"), and one keystroke stops trying further rules after 8 ms, re-runs included; how often that happens is counted for the Patterns page too. Saving unrelated settings (the community cache does it after each fetch) no longer resets what the guard learned. Literal snippets are not affected. There is no promise that a pattern runs in under a millisecond: a slow rule can cost a few keystrokes before it is switched off.
S-015 on the Espanso import path. Pattern rules from an Espanso file go through the same gate as rules typed on the Patterns page: each is checked with the pattern check at conversion and again, with the replacement limits, when the rules are planned and when Apply writes them (against the list as it is at that moment), and the 100 rule limit counts the rules you already have, so a file with 500 regex: entries or with ReDoS-shaped ones cannot put more than the limit, or an unchecked rule, into the list. The importer converts at most 1000 regex: matches of one file and the preview shows at most 50 rows per list. A stored patterns value that is not a list is never overwritten by an import.