fix: strip # prefix from tags in isTaskFile for tag-based identification#1607
Open
victoraraujo105 wants to merge 2 commits intocallumalpass:mainfrom
Open
fix: strip # prefix from tags in isTaskFile for tag-based identification#1607victoraraujo105 wants to merge 2 commits intocallumalpass:mainfrom
victoraraujo105 wants to merge 2 commits intocallumalpass:mainfrom
Conversation
Obsidian's metadata cache prepends '#' to frontmatter tag values (e.g., tags: [task] becomes ["#task"] in cache.frontmatter.tags). isTaskFile passes these raw values to matchesHierarchicalTagExact, which compares "#task" against the taskTag setting value "task" and fails to match. Strip the '#' prefix before comparing so tag-based task identification works correctly without requiring users to set taskTag to "#task".
Cover the fix for Obsidian metadata cache prepending '#' to frontmatter tags. Tests verify both '#'-prefixed and plain tags, hierarchical tags, case insensitivity, mixed formats, and edge cases.
b33dec1 to
7e4261c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
isTaskFilefails to match tasks when using tag-based identification because Obsidian's metadata cache prepends#to frontmatter tag valuestags: [task]in YAML becomes["#task"]incache.frontmatter.tags, causingmatchesHierarchicalTagExact("#task", "task")to returnfalse#prefix before passing tomatchesHierarchicalTagExactReproduction
taskTag: "task"(the default atsrc/settings/defaults.ts:262)tags: [task]in frontmatter (either via the plugin UI ortn create)tn listreturns 0 tasks despite files existing on disk:tn listcorrectly returns the created task.Root cause
TaskManager.isTaskFile()atsrc/utils/TaskManager.ts:103passes rawfrontmatter.tagsvalues (which include the#prefix from Obsidian's metadata cache) directly toFilterUtils.matchesHierarchicalTagExact(), which does an exact string comparison without accounting for the prefix.Before fix:
After fix:
Tests
Added 23 tests in
tests/unit/utils/TaskManager.isTaskFile.test.tscovering:#prefix) -- the primary bug scenario#prefix) -- backward compatibility#-prefixed and plain tags in same array#task/projectmatchingtask#Taskmatchingtask##task), bare#All 23 tests pass. No pre-existing tests were affected.
Test plan
isTaskFilereturnstruefortags: ["#task"]whentaskTagis"task"isTaskFilestill works for tags without#prefix#task/subtaskmatchestask)