mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-24 22:08:16 +00:00
* fix(wiki): keep valid Mermaid labels and link text through the sanitizer The wiki's Mermaid sanitizer turned some valid diagrams into invalid ones (#3705). `sanitizeMermaidLine` split each line on `EDGE_RE`, whose `\.\.+` alternative matched any run of dots, so the `...` inside a quoted label such as `A["value.when(...)"]` cut the label in two and the remainder was aliased as a node. The text of a `-- text -->` link was split off the same way and, when it held a dot, rewritten as a node reference: `N -- ref.invalidate --> A` became `N -- ref_invalidate["ref.invalidate"] --> A`. Both outputs fail `mermaid.parse`. Since the sanitizer runs again every time the viewer is rebuilt, a diagram fixed by hand broke again. Two changes: - The inside of every quoted string and every node shape (`[...]`, `(...)`, `{...}`) is masked with a placeholder before the line is split and unmasked after, so label text can never read as a link or a node. The delimiters stay, so the node sanitizer still sees where an inline label starts. - `EDGE_RE` matches the link forms Mermaid accepts: plain, thick and dotted (`-.->`, `-..-`), the piped label, and the labelled forms `-- text -->`, `== text ==>` and `-. text .->` as one token. Dots mean a link only in the dotted syntax. The three diagrams from the report now come out unchanged, dotted links still work, and the nodes around a labelled link are still aliased. Three unit tests cover that; the first and third fail on the previous sanitizer. The six existing tests pass unchanged. * fix(wiki): keep shaped nodes and chained links intact in the Mermaid sanitizer Two regressions from the first version of this branch, both found in review: - Rounded and circular nodes became invalid: with the label masked, the node id regex still swallowed the opening parenthesis of `A(Start)` and the restored label landed outside the generated shape. The id now stops where a shape opens (`[`, `(`, `{`). A call-shaped id such as `doc()` — a masked, empty pair of parentheses right after the id — is still one id and is repaired to `doc["doc()"]` as before. - A chained link split one node in two: the labelled-link alternative of EDGE_RE took `--- file.ts ---` for one link with text, so the middle node skipped aliasing while the next line aliased the same id. A labelled link now opens only with a bare `--`, `==` or `-.` followed by a space; a complete link never does. Thick links too. Parser-backed tests in test/unit/wiki-mermaid-sanitizer-parse.test.ts run the output through mermaid 11.17.2, the release the viewer loads, under jsdom, and compare the parsed graph: shaped nodes at both ends yield the same vertices and edges as the input; the plain and thick chains yield exactly A, file_ts, B, C with the three links; the report diagrams, the labelled link and the call-shaped id are checked the same way. mermaid and jsdom join the package's devDependencies for that file only. * fix(wiki): read compact head links as links and keep a call-shaped id's member chain Two cases from review: - `A --xfile.ts --> B`: Mermaid's lexer takes the longer match, so `--` followed by `-`, `>`, `x` or `o` is a link with a tail whatever comes next. The labelled-link opener excluded `x`/`o` only before a space, so `--xfile.ts -->` was taken for one labelled link and `file.ts` skipped aliasing on that line while the next line aliased it. The opener now excludes those four characters outright. - `foo().bar --> B`: the empty-parentheses rule absorbed `()` into the id but left `.bar` in the suffix, which was emitted after the generated label. The member chain that follows is part of the id, so `foo().bar` is one node again, `foo___bar["foo().bar"]`, as the previous sanitizer produced. Parser-backed tests for the compact cross and circle forms (three edges on one middle node) and for a qualified call-shaped id at both ends of a link. Both fail on the previous commit. * fix(wiki): preserve Mermaid graph identity with tiny parser coverage --------- Co-authored-by: Gergő Magyar <gergomagyar@icloud.com> Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> |
||
|---|---|---|
| .. | ||
| fixtures | ||
| helpers | ||
| integration | ||
| unit | ||
| utils | ||