Repository: platers/obsidian-linter (ts)

Issue:
Bug: forbidden character combinations while copy & pasting the text of a website to a note
I have this note:

![image](https://github.com/platers/obsidian-linter/assets/4138869/6953d532-e720-45d1-9b3b-6a5300e2fdf7)

with this markdown:


```

---
aliases: [avm, Fritz, Fritzbox, AX, Router, ntp, timeserver]
tags: [avm, FritzBox, Fritz, AX, Router, privat, account, ntp, timeserver, Zeitserver, Braunschweig]
filename: muell-Linter
erstellt: Donnerstag, 22. Februar 2024, 10:24:46 Uhr
geändert: Samstag, 06. April 2024, 22:48:11 Uhr
---

`

#`

```

If I linter it, the first "[" after "tags:" is deleted and at the end there is a ", `" instead of a "]":

![image](https://github.com/platers/obsidian-linter/assets/4138869/8f75f0ba-7e8f-4fb0-8b5e-b6727b6ff8e5)


[muell-Linter.md](https://github.com/platers/obsidian-linter/files/14894965/muell-Linter.md)

This causes after lintering again this error message:

![image](https://github.com/platers/obsidian-linter/assets/4138869/2fd60b46-540d-4304-b84d-13eed7bfefa7)

(Background: I copied the text part of this website https://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working/ and pasted it into a note. This error occured, but I've narrowed it down.)

It would be nice, if your linter plugin could recognize issues like this and repair them.



Pull request description:
Fix: Make Sure Tags Do Not Have "`" in Them
Fixes #1068 

There was a report that in a specific instance there was an issue where pasting content was causing issues when it was linted. I looked into it and found that the problem was that we were allowing "`" to be a tag character. Adding it to the values to ignore for a tag fixes the problem.

Changes Made:
- Added a test for this scenario
- Added "`" to the list of characters to not allow in a tag

Patch:
diff --git a/src/utils/regex.ts b/src/utils/regex.ts
index 1059ba4..207f861 100644
--- a/src/utils/regex.ts
+++ b/src/utils/regex.ts
@@ -13,7 +13,7 @@ export const codeBlockRegex = new RegExp(`${backtickBlockRegexTemplate}|${tildeB
 export const wikiLinkRegex = /(!?)\[{2}([^\][\n|]+)(\|([^\][\n|]+))?(\|([^\][\n|]+))?\]{2}/g;
 // based on https://davidwells.io/snippets/regex-match-markdown-links
 export const genericLinkRegex = /(!?)\[([^[]*)\](\(.*\))/g;
-export const tagWithLeadingWhitespaceRegex = /(\s|^)(#[^\s#;.,><?!=+{\]]+)/g;
+export const tagWithLeadingWhitespaceRegex = /(\s|^)(#[^\s#;.,><?!=+{`\]]+)/g;
 export const obsidianMultilineCommentRegex = /^%%\n[^%]*\n%%/gm;
 export const wordSplitterRegex = /[,\s]+/;
 export const ellipsisRegex = /(\. ?){2}\./g;


Test patch:
diff --git a/__tests__/move-tags-to-yaml.test.ts b/__tests__/move-tags-to-yaml.test.ts
index 7315a3b..c85dede 100644
--- a/__tests__/move-tags-to-yaml.test.ts
+++ b/__tests__/move-tags-to-yaml.test.ts
@@ -297,5 +297,31 @@ ruleTest({
         tagArrayStyle: TagSpecificArrayFormats.SingleStringSpaceDelimited,
       },
     },
+    { // accounts for https://github.com/platers/obsidian-linter/issues/1068
+      testName: 'Make sure that "`" is not valid in a tag',
+      before: dedent`
+        ---
+        title: Note
+        Date: 2023-10-24T23:00:00+08:00
+        lastMod: 2023-11-28T17:36:29+08:00
+        tags: [text, val2]
+        ---
+        ${''}
+        #\`
+      `,
+      after: dedent`
+        ---
+        title: Note
+        Date: 2023-10-24T23:00:00+08:00
+        lastMod: 2023-11-28T17:36:29+08:00
+        tags: [text, val2]
+        ---
+        ${''}
+        #\`
+      `,
+      options: {
+        tagArrayStyle: NormalArrayFormats.SingleLine,
+      },
+    },
   ],
 });