Flat-Badger-1971 / ArchiveHelper

0 stars 1 forks source link

string.find uses pattern matching by default. Care should be taken when searching for hyphens and other special characters. #6

Closed Stemuweb closed 5 months ago

Stemuweb commented 5 months ago

The problem has been detected with the french equivalent of the tomeshell: "tome-carapace"

The hyphen character (-) is used in the lua pattern matching. The method string.find uses pattern matching by default.

local str = "tome-carapace" local pos = str:find(str) -- pos is nil

There is (at least) three solutions :

1) Only replace the calls to the string.find function in tomeCheck() with equals

if ((targetName == tomeName) or (sourceName == tomeName) then

2) Escape the hyphen character in the translated strings when used : "tome%-carapace" (maybe with a comment in the languages files to warn future translators)

local str = "tome%-carapace" local pos = str:find(str) -- pos is 1

3) Change to exact matching everywhere string.find is used, to be safe whatever the translations in the future.

local str = "tome-carapace" local pos = str:find(str, 1, true) -- pos is 1

What is your preference ?

Flat-Badger-1971 commented 5 months ago

Well spotted - I had not considered the pattern matching issue - I'll go with option 3 I think.

Flat-Badger-1971 commented 5 months ago

added - will push shortly