Page 1 of 1

Possibly unintended behavior when a tag contains <crlf>

Posted: 21 Aug 2024 22:18
by o7blue
This is easily remedied just by running replacelist($string, <crlf>, ""), but I'm not sure if the consequences of having a <crlf> slip into the tags is intended.

I use a script to tag items, then I have a couple db's that store their own tag clouds. Before I realized I had a trailing <crlf> in my tag, this is what happened:

-My script would tag the items properly
-When I switched tag cloud to db2, tagexport() saved the tags properly to db1
-When switching back to db1 tagload() just wouldn't load anything from db1, resulting in an empty tag list
-Switching away would save the current empty taglist to db1, overwriting the previous entries, resulting in those tags being lost

There's a warning pop-up when trying to pass a " into the tags, and I was wondering if something similar shouldn't be done for <crlf>? It's an invisible character and it could take a bit to figure out that it's causing issues.

Re: Possibly unintended behavior when a tag contains <crlf>

Posted: 21 Aug 2024 22:28
by highend
As a scripter you are responsible for not adding a <crlf> to a tag.
It will break the structure of the tags.dat file^^

Btw, replacelist is not the command of choice if this is not really about replacing multiple characters, use replace instead

Re: Possibly unintended behavior when a tag contains <crlf>

Posted: 21 Aug 2024 23:24
by o7blue
Agreed, but is there even a valid case for <crlf> in a tag? I wouldn't even think about posting if xy allowed me to put a quote in a tag breaking everything (I mean it is my fault for putting in disallowed characters), but there is a warning against that. On my end I know I'm responsible for not passing in garbage data, but on xy's end I found a quote triggering a warning and <crlf> not triggering anything just a little bit inconsistent. Unless there's a use case I'm missing?

Thanks for pointing out replace(), I'll use that instead for this.

Re: Possibly unintended behavior when a tag contains <crlf>

Posted: 22 Aug 2024 00:07
by highend
but on xy's end I found a quote triggering a warning and <crlf> not triggering anything
Via scripting? Show the code...

Re: Possibly unintended behavior when a tag contains <crlf>

Posted: 22 Aug 2024 08:56
by o7blue
For example I can run this

Code: Select all

tagitems("tags", "test_tag_1: "yes"", "E:\Downloads\tmp\tmp.txt");
Which will result in this window popping up during execution:
1.PNG
1.PNG (3.62 KiB) Viewed 3540 times
On the other hand this

Code: Select all

tagitems("tags", "test_tag_1: yes<crlf>", "E:\Downloads\tmp\tmp.txt");
Doesn't complain and actually tags the item with the bad character.


edit: I should also mention it's not like I was putting in the <crlf> on purpose originally. I just didn't realize runret() was giving me back a string with a trailing <crlf>.

Re: Possibly unintended behavior when a tag contains <crlf>

Posted: 22 Aug 2024 09:46
by admin
I changed tagitems() like this:

Code: Select all

    * SC tagitems: Now the command processes the input data just like the "Tags | Tags | 
      Edit Tags..." dialog. Multiple tags can be separated by either , (comma) or CRLF 
      (line feed). For example:
        tagitems("tags", "yes,no");       //sets tags "yes" and "no" to the selected item(s)
        tagitems("tags", "yes<crlf>no");  //sets tags "yes" and "no" to the selected item(s)
      Previously, <crlf> was not handled at all and resulted in a corrupt tag database entry.

Re: Possibly unintended behavior when a tag contains <crlf>

Posted: 23 Aug 2024 03:35
by o7blue
Thank you for addressing this :tup: