Delimiter bug

Here’s an interesting bug — in Mojave, at least. When the only text item in a specified range of them is “”, extracting that range returns an empty list instead of {“”}!

set word1 to "eider"
set word2 to "lorelei"
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "ei"
set ti1 to word1's text items
set ti1a to word1's text items 1 thru -2
set ti2 to word2's text items
set ti2a to word2's text items 2 thru -1
set AppleScript's text item delimiters to astid

{ti1, ti1a, ti2, ti2a}
--> {{"", "der"}, {}, {"lorel", ""}, {}}

Behaves the same under 10.13.6.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 10 février 2021 15:46:37

I get the same result under Catalina.

I see it is bad programming of thru command. Because returning text items 2 and -1 of word2 one by one gives correct results.


set word2 to "lorelei"
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "ei"
set item2 to word2's text item 2
set item_1 to word2's text item -1
set AppleScript's text item delimiters to astid

{item2, item_1} --> {"",""}

thru is correctly used but here it fails because it’s applied to a list containing a single empty string.

Just for see I changed the original strings so that the Nigel’s code generate lists of two items.

set word1 to "eieider" -- EDITED
set word2 to "loreleiei" -- EDITED
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "ei"
set ti1 to word1's text items
set ti1a to word1's text items 1 thru -2
set ti2 to word2's text items
set ti2a to word2's text items 2 thru -1
set AppleScript's text item delimiters to astid

{ti1, ti1a, ti2, ti2a}
--> {{"", "", "der"}, {"", ""}, {"lorel", "", ""}, {"", ""}}

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 10 février 2021 19:47:45

I’m saying the thru command contains a bug on the Apple side, not because you misuse it.