Possibly unintended behavior when a tag contains <crlf>

Discuss and share scripts and script files...
Post Reply
o7blue
Posts: 116
Joined: 22 Dec 2020 07:10

Possibly unintended behavior when a tag contains <crlf>

Post 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.

highend
Posts: 14578
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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
One of my scripts helped you out? Please donate via Paypal

o7blue
Posts: 116
Joined: 22 Dec 2020 07:10

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

Post 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.

highend
Posts: 14578
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post by highend »

but on xy's end I found a quote triggering a warning and <crlf> not triggering anything
Via scripting? Show the code...
One of my scripts helped you out? Please donate via Paypal

o7blue
Posts: 116
Joined: 22 Dec 2020 07:10

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

Post 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 3538 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>.

admin
Site Admin
Posts: 65012
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

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

Post 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.

o7blue
Posts: 116
Joined: 22 Dec 2020 07:10

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

Post by o7blue »

Thank you for addressing this :tup:

Post Reply