[Bug]: json.fromList and stringToList does not work with period delimiter
Describe the Bug
If calling either stringToList or json.fromList with a period for alternative delimiter, the result is an empty list.
This does not appear to be an issue with e.g. listCount.
As it turns out, the delimiter parameter is treated as a regex pattern, and thus it tries to match against every single character instead.
A workaround is to pass "\." as the delimiter.
To Reproduce
This small script will illustrate the issue:
[h:first = "0.0.1"]
[h:second = "0.0.2"]
[h:fails = json.fromList(libVersion, ".")]
[h:works = json.fromList(libLatest, "\\.")]
[h:result = json.set("{}", "Fails", fails, "Works", works)]
[h:broadcast("<pre>" + json.indent(result) + "</pre>")]
Expected Behaviour
I expect the stringToList or json.fromList to produce a list of values without having to escape the period.
Screenshots
No response
MapTool Info
1.13.2
Desktop
Windows 11
Additional Context
No response
For stringToList(), the 2nd parameter (pattern) is intentionally a regex as the separator could be more complex than any literal string (otherwise it would already be a string list). The 3rd parameter (delim) is interpreted literally.
By digging through the codebase, I found these to be all the functions to be affected by the same problem:
-
json.toList() -
json.fromStrProp() -
execLink() -
execFunction() -
selectTokens() -
deselectTokens() -
broadcast() -
exposeFOW() -
input()("DELIMITER="option for lists and radios)
Had to amend the test script provided in the bug report to:
[h:libVersion = "0.0.1"]
[h:libLatest = "0.0.2"]
[h:fails = json.fromList(libVersion, ".")]
[h:works = json.fromList(libLatest, "\\.")]
[h:result = json.set("{}", "Fails", fails, "Works", works)]
[h:broadcast("<pre>" + json.indent(result) + "</pre>")]
Test results in 1.14.3
{
"Fails": [],
"Works": [
0,
0,
2
]
}
vs Test Results in 1.15.0
{
"Fails": [
0,
0,
1
],
"Works": ["0.0.2"]
}
Also ran a test in both 1.14.3 vs 1.15.0 using the following:
[broadcast("Fails in 1.14.3 and works in 1.15.0", getPlayerName()+".someoneMadeUp", ".")]
[broadcast("Works in 1.14.3 and fails in 1.15.0", getPlayerName()+".someoneMadeUp", "\\.")]
So while what was failing before now works, what worked before (even though it was a workaround!) now fails, so may be a breaking change for some framework developers who use any of the functions and escaped full stop delimiters affected by this change.