obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

Dataview parse error if tag contains some special charaters

Open AlphaLiu opened this issue 3 years ago • 6 comments
trafficstars

What happened?

If I wrote a dv snippet to query a tag wihich contains some special charaters, like "." or "·" or "&" etc., dv shows error with following message.

Dataview: Error: 
-- PARSING FAILED --------------------------------------------------

> 1 | list from #tagA.b
    |                ^
  2 | 

Expected one of the following: 

'and' or 'or', /FROM/i, EOF, FLATTEN <value> [AS <name>], GROUP BY <value> [AS <name>], LIMIT <value>, SORT field [ASC/DESC], WHERE <expression>, text

DQL

list from #tagA.b

JS

No response

Dataview Version

0.5.38

Obsidian Version

0.14.15

OS

Windows

AlphaLiu avatar Jul 02 '22 10:07 AlphaLiu

I don't think that is a specific Dataview issue. Why? Because I guess you're talking about a tag created in frontmatter... Something like:

---
tags: tag.1
---

If you try to write the tag in the middle of you note content, Obsidian doesn't recognize the #tag.1, only #tag (.1 remain separated from the recognized tag). Because they're some prohibited characters.

For dataview the field tags: in frontmatter remains as a normal field (with the key-name "tags") and "tag.1" is recognized as a value. It is Obsidian that recognize the field with the name "tag" or "tags" and convert the values to real file tags. In the case, I guess Obsidian is able to recognize tag.1 as #tag.1 if the value is in a tag field in frontmatter, but don't recognize #tag.1 if in the main content.

Based in the normal behavior (tags in content) I guess the developer followed the obsidian rules and did not consider the possibility of "prohibited" characters in tags when in from/source command.

mnvwvnm avatar Jul 02 '22 17:07 mnvwvnm

Dataview will actually parse the tags correctly in this case, but the query parser doesn't understand the '.' specifically. This seems a little hard to fix in general, especially if Obsidian allows you to use arbitrary characters. I'll have to experiment.

blacksmithgu avatar Jul 03 '22 00:07 blacksmithgu

I wonder if we can temporarily get around this by using a where condition. Seems like it should work in theory.

AB1908 avatar Jul 03 '22 01:07 AB1908

I don't think that is a specific Dataview issue. Why? Because I guess you're talking about a tag created in frontmatter... Something like:

---
tags: tag.1
---

If you try to write the tag in the middle of you note content, Obsidian doesn't recognize the #tag.1, only #tag (.1 remain separated from the recognized tag). Because they're some prohibited characters.

For dataview the field tags: in frontmatter remains as a normal field (with the key-name "tags") and "tag.1" is recognized as a value. It is Obsidian that recognize the field with the name "tag" or "tags" and convert the values to real file tags. In the case, I guess Obsidian is able to recognize tag.1 as #tag.1 if the value is in a tag field in frontmatter, but don't recognize #tag.1 if in the main content.

Based in the normal behavior (tags in content) I guess the developer followed the obsidian rules and did not consider the possibility of "prohibited" characters in tags when in from/source command.

YES , I was using the tags in frontmatter. OBSIDIAN could recognize it and find out all notes who have this tag.

AlphaLiu avatar Jul 03 '22 02:07 AlphaLiu

Yes, as said before Obsidian recognize it if in the frontmatter. As suggested by @AB1908, you can contour this with the WHERE condition (however in performance side isn't the same thing, I guess). By two ways: 1 - by "file.tags" or "file.etags"

WHERE contains(file.tags, "#tag.1")

2 - by "tags" (or "tag", i.e. the key you write in frontmatter):

WHERE contains(tags, "tag.1")

if only one tag per file you can use WHERE tags = "tag.1" instead of contains.

mnvwvnm avatar Jul 03 '22 09:07 mnvwvnm

Yes, as said before Obsidian recognize it if in the frontmatter. As suggested by @AB1908, you can contour this with the WHERE condition (however in performance side isn't the same thing, I guess). By two ways: 1 - by "file.tags" or "file.etags"

WHERE contains(file.tags, "#tag.1")

2 - by "tags" (or "tag", i.e. the key you write in frontmatter):

WHERE contains(tags, "tag.1")

if only one tag per file you can use WHERE tags = "tag.1" instead of contains.

Thank you! This could solved my problem.

AlphaLiu avatar Jul 04 '22 05:07 AlphaLiu