Fix character disappearing and false matching issues in TiddlyWiki 5.4 Freelink plugin#9397
Conversation
False positive matches Symptom: Words like "it is", "Choose", "Set up" are incorrectly linked to tiddler "FooBar" when a tiddler titled "xxx x FooBar" exists. Root cause: The Aho-Corasick algorithm's output merging mechanism in buildFailureLinks caused failure link outputs to be incorrectly merged into intermediate nodes, resulting in false matches. Fix: Remove incorrect output merging in buildFailureLinks Implement proper output collection during search by traversing the failure link chain Add exact match validation: verify that the matched text exactly equals the pattern before accepting it Add cycle detection to prevent infinite loops in failure link traversal
First character disappearing Symptom: When freelinking is enabled, the first character of matched words disappears (e.g., "The" becomes "he", "Filter" becomes "ilter"). Root cause: When the current tiddler's title was being filtered out, it was done too late in the process (during parse tree construction), causing text rendering issues. Fix: Move the current tiddler title filtering to the match validation stage (in processTextWithMatches) Use substring instead of slice for better stability Add proper case-insensitive comparison for title matching
add back description
add back description
✅ Deploy Preview for tiddlywiki-previews ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Confirmed: s793016 has already signed the Contributor License Agreement (see contributing.md) |
add freelinks plugin for testing
restore
add freelinks plugin for test
| child.$.push.apply(child.$, failureOutput.$); | ||
| } | ||
|
|
||
| // Critical fix: remove incorrect output merging |
There was a problem hiding this comment.
AI like adding these useless comment. we don't need them in the code.
This is legacy feature of AI that used to work as Edit mode. Modern Agent mode AI can directly say these info in the chat, but they still like to add these things into the code.
|
I'm not sure how to test this, can you try read existing test edition and try add two tests for this feature and bug issue? |
|
Thanks for looking into this!
Hm, that is now quite how it appeared for me. My bug demo here shows the topmost tiddler like this:
...i.e there it is actually the whole first word of those sentences, not just the first letter, that disappear. Maybe you PR fixes this but I'm saying it, just to make sure this was not missed. |
|
@twMat Did you test with this preview: https://deploy-preview-9397--tiddlywiki-previews.netlify.app/ It contains the freelinks plugin now. So you can directly test from there. |
|
I only did a very short test and it looks better now. |
erase comment
erase comment
| var failureLink = (fail && fail[char]) ? fail[char] : root; | ||
| this.failure[child] = failureLink; | ||
|
|
||
| // Critical fix: remove incorrect output merging |
There was a problem hiding this comment.
IMO Critical fix should have been removed, but the rest seems to be important to understand the code. so this may stay
| var char = text[i]; | ||
| var transitionCount = 0; | ||
|
|
||
| // Follow failure links to find a valid transition |
| var visitedNodes = new Set(); | ||
|
|
||
| while(currentNode && collectCount < 10) { | ||
| // Prevent infinite loops |
| } | ||
| visitedNodes.add(currentNode); | ||
|
|
||
| // Only collect outputs from the current node (not merged ones) |
add back some commets
| var failureLink = (fail && fail[char]) ? fail[char] : root; | ||
| this.failure[child] = failureLink; | ||
|
|
||
| // remove incorrect output merging |
There was a problem hiding this comment.
As I wrote. The comment // remove incorrect output merging can be removed. The rest can probably stay.
| } | ||
| } | ||
|
|
||
| // correctly collect all matches |
clean comment
|
I've prepared another test package here: test by ai3.json This collection of tiddlers is designed to test the reliability, accuracy, and performance of the Freelinks plugin for TiddlyWiki. It provides structured test cases to ensure that automatic link generation behaves correctly in various real-world scenarios. !! 📘 Purpose
!! 🧩 How to Use
!! ⚙️ Notes
!! ✅ Expected Outcome
|
| "tiddlywiki/confetti", | ||
| "tiddlywiki/dynannotate", | ||
| "tiddlywiki/internals", | ||
| "tiddlywiki/freelinks", |
There was a problem hiding this comment.
This plugin will need to be removed once you are sure, that everything works as expected.
reversed to original
update detail
|
Thank you @s793016. I think it's not clear in the documentation that change notes can have multiple GitHub links as shown in this example. In the case of a bugfix like this, you can just add the bugfix PR to the GitHub links for the original PR. |
another link added
✅ Change Note StatusAll change notes are properly formatted and validated! 📝 $:/changenotes/5.4.0/#9397Type: bugfix | Category: plugin
👥 Contributors: s793016 📖 Change Note GuidelinesChange notes help track and communicate changes effectively. See the full documentation for details. |
add "release: 5.4.0"
| change-type: bugfix | ||
| change-category: plugin | ||
| github-links: [https://github.com/TiddlyWiki/TiddlyWiki5/pull/9397](https://github.com/TiddlyWiki/TiddlyWiki5/pull/9397) | ||
| github-links: [https://github.com/TiddlyWiki/TiddlyWiki5/pull/9084](https://github.com/TiddlyWiki/TiddlyWiki5/pull/9084), [https://github.com/TiddlyWiki/TiddlyWiki5/pull/9397](https://github.com/TiddlyWiki/TiddlyWiki5/pull/9397) |
There was a problem hiding this comment.
| github-links: [https://github.com/TiddlyWiki/TiddlyWiki5/pull/9084](https://github.com/TiddlyWiki/TiddlyWiki5/pull/9084), [https://github.com/TiddlyWiki/TiddlyWiki5/pull/9397](https://github.com/TiddlyWiki/TiddlyWiki5/pull/9397) | |
| github-links: https://github.com/TiddlyWiki/TiddlyWiki5/pull/9084 https://github.com/TiddlyWiki/TiddlyWiki5/pull/9397 |
Markdown links do not work with TiddlyWiki.
some format modified
|
@Jermolene ... The new freelinks functions have been merged. So IMO this one needs to be merged too. |
|
Thanks @s793016 |
update the existing release note with the new PR link instead of creating a new release note.
update the existing release note with the new PR link instead of creating a new release note.
…t-match, and Unicode safety (#9676) * Update aho-corasick.js fix transition logic; ensure complete outputs (via failure-output merge); clean up stats/build scoping; clarify CJK boundary behavior. * Update text.js implement global longest-match priority with overlap suppression; fix refresh invalidation to ignore $:/state and drafts; handle deletions precisely to avoid rebuilding on draft deletion; add defensive check for cached automaton presence. * Update text.js remove comment * Update aho-corasick.js remove comment * Create #9672.tid * Create #2026-0222.tid * Delete editions/tw5.com/tiddlers/releasenotes/5.4.0/#2026-0222.tid * Update text.js remove \" * Update and rename #9672.tid to #9676.tid change to right number * Update #9397.tid update the existing release note with the new PR link instead of creating a new release note. * Delete editions/tw5.com/tiddlers/releasenotes/5.4.0/#9676.tid update the existing release note with the new PR link instead of creating a new release note. * Rename #9397.tid to #9676.tid update the existing release note with the new PR link instead of creating a new release note. * Update and rename #9676.tid to #9397.tid add link * Rename #9397.tid to #9676.tid * Update tiddlywiki.info add plugin for test build * Update tiddlywiki.info reverse change, ready to be merge.


This PR fixes two critical bugs in the freelinks plugin when running on TiddlyWiki 5.4:
Bug 1: First character disappearing
Symptom:
When freelinking is enabled, the first character of matched words disappears (e.g., "The" becomes "he", "Filter" becomes "ilter", "5.4.0" becomes ".4.0", ).
Root cause:
When the current tiddler's title was being filtered out, it was done too late in the process (during parse tree construction), causing text rendering issues.
Fix:
Bug 2: False positive matches
Symptom:
Words like "it is", "Choose", "Set up" are incorrectly linked to tiddler "FooBar" when a tiddler titled "xxx x FooBar" exists.
Root cause:
The Aho-Corasick algorithm's output merging mechanism in buildFailureLinks caused failure link outputs to be incorrectly merged into intermediate nodes, resulting in false matches.
Fix:
Test case
Import attached file to reproduce both bugs:
test2.json
With Word Boundary Check enabled and Ignore Case disabled, both bugs should be fixed.