View Issue Details

IDProjectCategoryView StatusLast Update
0002176AniDB AppletBug Reportpublic2014-10-27 13:33
Reporternponobeghuk Assigned ToDvdKhl  
PrioritynormalSeverityminorReproducibilityalways
Status confirmedResolutionopen 
Summary0002176: Tagging system script parser: conditional statement - unnecesary evaluation of the expression which not matched by the condition
DescriptionI've been trying to adjust the tagging system script to rename files for me in the fashion I wanted to.
One of the elements I desired to have is to have a subfolder containing the language of the subtitles in the name.
Since a lot of files have several subtitle tracks, I ended up having something like "\spanish'english sub\" which is useless
I made a simple function to retrieve substring only up to the first apostrophe, which looked like this:

GetFirstTok(str,separator) := { $indexof(%str%, %separator%)="-1" ? %str% : $substr(%str%, "0", $indexof(%str%, %separator% ))}

and used later with this: FirstLang:={%FSLng% = "raw"?%FSLng%:$GetFirstTok(%FSLng%,"'")" sub"}

While the function worked flawlessly with files with several subtitle tracks, it actually threw a "String index out of range: -1" error each time
I tried to use the script to rename single subtitle track files. I found out, the script parser was trying to evaluate the "false" part of the conditional
statement even though the condition itself evaluated to "true" and there is no need to check the "false" part at all.

When I tried to check the function without actually reading files, I created a temporary variable, assigned string "spanish" to it and tried passing it to
the function above, and print the result by appending it to the %PathName% variable and it actually worked. However, upon reading a file, the same line of code
fired an error, so it must be a runtime-only issue.

I used a workaround of changing the third $substr parameter to $max("0",$indexof(%str%, %separator% )) to make sure it never goes below 0, which worked.
However, I believe this is not the intended behavior, so decided to report it.

Regards,
Bob.
Steps To Reproduce###### try this on any file with a single subtitle track
#GetFirstTok(str,separator) := { $indexof(%str%, %separator%)="-1" ? %str% : $substr(%str%, "0", $max("0",$indexof(%str%, %separator% )))} 
#Above works correctly for both single- and multi- subtitle track files




GetFirstTok(str,separator) := { $indexof(%str%, %separator%)="-1" ? %str% : $substr(%str%, "0", $indexof(%str%, %separator% ))}
#Above results in: String index out of range: -1 | Error at Row: 10 Column: 43




#GetFirstTok(str,separator) := { $indexof(%str%, %separator%)="-1" ? %str% : "false"}
#Above works as intended for single subtitle language file which I used, the string "false" is never actually used anywhere.


PathName := "F:\"$GetFirstTok(%FSLng%,"'")"\"

FileName:=%CurrentFN%
TagsNo tags attached.

Activities

DvdKhl

2014-10-27 11:57

developer   ~0003491

Last edited: 2014-10-27 13:33

Yes, the tagging system is not really good in that regard.
It evaluates while parsing, with the side effect that everything is evaluated.

I don't really want to poke the tagging system for now and if I do I'm more inclined to add proper sandboxed javascript support and let the old tagging system deprecate.

As a workaround, some regex magic:
$repl(%ACatList%, "([^']*).*", "$1")
(i.e. parse until first ', store it, parse rest, replace everything parsed with stored value)

nponobeghuk

2014-10-27 13:25

reporter   ~0003492

I was reluctant to use regex at first since the use of capturing groups wasn't documented on the wiki page.

However, this indeed looks like a much more elegant approach to the same problem, I'll try it as soon as I'm able to.

Thanks for your time,
Bob.

Issue History

Date Modified Username Field Change
2014-10-27 03:31 nponobeghuk New Issue
2014-10-27 11:57 DvdKhl Note Added: 0003491
2014-10-27 11:58 DvdKhl Assigned To => DvdKhl
2014-10-27 11:58 DvdKhl Status new => confirmed
2014-10-27 13:25 nponobeghuk Note Added: 0003492
2014-10-27 13:33 DvdKhl Note Edited: 0003491