Skip to content

Commit 162f0ac

Browse files
authored
Merge pull request #1306 from nshcr/fix-yaml-title-regex
fix: correct regex pattern for title matching in yaml-title rule
2 parents b4dd3d9 + 1fdfb39 commit 162f0ac

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

__tests__/yaml-title.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,22 @@ ruleTest({
357357
# [test \#4](github.com/platers/obsidian-linter)
358358
`,
359359
},
360+
{
361+
testName: 'Only matches and replaces the correct title key, not similar keys',
362+
before: dedent`
363+
---
364+
title2: ShouldNotChange
365+
title: ShouldChange
366+
---
367+
# Hello world
368+
`,
369+
after: dedent`
370+
---
371+
title2: ShouldNotChange
372+
title: Hello world
373+
---
374+
# Hello world
375+
`,
376+
},
360377
],
361378
});

src/rules/yaml-title.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class YamlTitle extends RuleBuilder<YamlTitleOptions> {
5151
title = escapeStringIfNecessaryAndPossible(title, options.defaultEscapeCharacter);
5252

5353
return formatYAML(text, (text) => {
54-
const title_match_str = `\n${options.titleKey}.*\n`;
54+
const title_match_str = `\n${options.titleKey}:.*\n`;
5555
const title_match = new RegExp(title_match_str);
5656
if (title_match.test(text)) {
5757
text = text.replace(

0 commit comments

Comments
 (0)