@@ -1303,16 +1303,42 @@ export class MarkdownTaskParser {
13031303 return metadata ;
13041304 }
13051305
1306+ /**
1307+ * Normalize a tag to ensure it has a # prefix
1308+ * @param tag The tag to normalize
1309+ * @returns Normalized tag with # prefix
1310+ */
1311+ private normalizeTag ( tag : string ) : string {
1312+ if ( typeof tag !== 'string' ) {
1313+ return tag ;
1314+ }
1315+
1316+ // Trim whitespace
1317+ const trimmed = tag . trim ( ) ;
1318+
1319+ // If empty or already starts with #, return as is
1320+ if ( ! trimmed || trimmed . startsWith ( '#' ) ) {
1321+ return trimmed ;
1322+ }
1323+
1324+ // Add # prefix
1325+ return `#${ trimmed } ` ;
1326+ }
1327+
13061328 /**
13071329 * Merge tags from different sources, removing duplicates
13081330 * @param baseTags Base tags array (from task)
13091331 * @param inheritedTags Tags to inherit (from file metadata)
13101332 * @returns Merged tags array with duplicates removed
13111333 */
13121334 private mergeTags ( baseTags : string [ ] , inheritedTags : string [ ] ) : string [ ] {
1313- const merged = [ ...baseTags ] ;
1335+ // Normalize all tags before merging
1336+ const normalizedBaseTags = baseTags . map ( tag => this . normalizeTag ( tag ) ) ;
1337+ const normalizedInheritedTags = inheritedTags . map ( tag => this . normalizeTag ( tag ) ) ;
1338+
1339+ const merged = [ ...normalizedBaseTags ] ;
13141340
1315- for ( const tag of inheritedTags ) {
1341+ for ( const tag of normalizedInheritedTags ) {
13161342 if ( ! merged . includes ( tag ) ) {
13171343 merged . push ( tag ) ;
13181344 }
@@ -1461,7 +1487,9 @@ export class MarkdownTaskParser {
14611487 inherited [ "tags" ] === null ||
14621488 inherited [ "tags" ] === "" )
14631489 ) {
1464- inherited [ "tags" ] = JSON . stringify ( value ) ;
1490+ // Normalize tags before storing
1491+ const normalizedTags = value . map ( tag => this . normalizeTag ( tag ) ) ;
1492+ inherited [ "tags" ] = JSON . stringify ( normalizedTags ) ;
14651493 }
14661494 } else {
14671495 // Only inherit if:
0 commit comments