Repository: platers/obsidian-linter (ts)

Issue:
Bug: Linter fails to property delimit frontmatter tags separated by commas
## Describe the Bug

If a note's frontmatter contains tags that are delimited by a comma without a trailing space, linter treats them as a single tag.

## How to Reproduce

I have attached the data.json file. [data.json.txt](https://github.com/platers/obsidian-linter/files/10057774/data.json.txt)

### Example 1

include in frontmatter YAML:

`tags: tag1,tag2`

### Example 2

include in frontmatter YAML:

`tags: tag1,tag2, tag3`

Linting the file produces an incorrect result when the tags array is split into a multiline array:

Example 1 produces no result, even though it contains two tags.

Example 2 produces a note that now only contains 2 tags ("tag1,tag2" and "tag3") even though before linting the note contained three tags.

## Expected Behavior

Linter should parse the tags array **exactly** how Obsidian parses the tags array.

Example 1 should produce a multiline tags array with two tags.
Example 2 should produce a multiline tags array with three tags.

## Device

- [x] Desktop
- [?] Mobile


Pull request:
Fix Issue with Comma Delimiter not Working if You Have a Space after Some Commas and Not Others
Fixes #509 

Changes Made:
- Made sure that single-line arrays and single-line comma delimited strings for tags are split on a comma instead of a comma followed by a space and they have whitespace trimmed off of them
- Added a test to make sure this functionality continues to work in the future

Patch:
diff --git a/src/utils/yaml.ts b/src/utils/yaml.ts
index 4882d94..d4290eb 100644
--- a/src/utils/yaml.ts
+++ b/src/utils/yaml.ts
@@ -190,9 +190,7 @@ export function splitValueIfSingleOrMultilineArray(value: string): string | stri
       return null;
     }
 
-    let arrayItems = value.split(', ');
-
-    arrayItems = arrayItems.length > 1 ? arrayItems : arrayItems[0].split(',');
+    const arrayItems = value.split(',').map((val: string) => val.trim());
 
     return arrayItems.filter((el: string) => {
       return el != '';
@@ -232,7 +230,7 @@ export function convertTagValueToStringOrStringArray(value: string | string[]):
   if (Array.isArray(value)) {
     originalTagValues = value;
   } else if (value.includes(',')) {
-    originalTagValues = value.split(', ');
+    originalTagValues = value.split(',').map((val: string) => val.trim());
   } else {
     originalTagValues = value.split(' ');
   }


Test patch:
diff --git a/__tests__/format-yaml-arrays.test.ts b/__tests__/format-yaml-arrays.test.ts
index 122b5c7..82daab6 100644
--- a/__tests__/format-yaml-arrays.test.ts
+++ b/__tests__/format-yaml-arrays.test.ts
@@ -217,6 +217,26 @@ ruleTest({
         tagArrayStyle: SpecialArrayFormats.SingleStringToMultiLine,
       },
     },
+    { // accounts for https://github.com/platers/obsidian-linter/issues/509
+      testName: 'Convert tags from single-line array to multi-line array when there is no space after one of the commas and the key for tags is `tag`',
+      before: dedent`
+        ---
+        tag: [tag1,tag2, tag3, tag4]
+        ---
+      `,
+      after: dedent`
+        ---
+        tag:
+          - tag1
+          - tag2
+          - tag3
+          - tag4
+        ---
+      `,
+      options: {
+        tagArrayStyle: NormalArrayFormats.MultiLine,
+      },
+    },
 
     // aliases
     {