gnosygnu / xowa

xowa offline wiki application
Other
374 stars 41 forks source link

Script error: =Module:convert:328 attempt to compare nil with number #520

Closed desb42 closed 5 years ago

desb42 commented 5 years ago

Looking at page en.wikipedia.org/wiki/Extremophile the above error occurred

The wikitext producing this error is:

{{Convert|45–122|C|}}

I have tracked this down to Module:Convert Line 328 reads:

if limit and ulen(s) > limit then

it is the ulen(s) that is producing nil

However, this is inside an error routine - which should not have occurred This looks to be something to do with the unicode/utf-8 issues of #504

The two lines

{{Convert|45–122|C|}}
{{Convert|45-122|C|}}

(different 'minus' signs) produce in Mediawiki

45–122 °C (113–252 °F) 45–122 °C (113–252 °F)

In xowa-gui

[convert: needs another number] Script error: =Module:convert:328 attempt to compare nil with number
gnosygnu commented 5 years ago

Ugh, ugh, ugh, ugh!

This is a bad bug. It can cause all types of weird behavior, especially since it sits deep down in a core LuaJ string library.

I updated the LuaJ library just now. Please bring that one down. If your 2019-06 is using a build from the #504 fix, then I would stop it and start again. Sorry.

Otherwise, thanks for finding this bug so early! Also, your instincts were uncanny in linking this to #504.

More detail below.

Thanks!


As mentioned above, this bug was related to #504 . The #504 fix had one minor but significant flaw

Because of #504, the code became something like this:

        LuaString rv = LuaString.valueOfCopy(src_as_lstr.m_bytes, bgn, end - bgn);

Instead, it needed to be something like this:

        LuaString rv = LuaString.valueOfCopy(src_as_lstr.m_bytes, src_as_lstr.m_offset + bgn, end - bgn);

The missing m_offset does a lot of weird things. In the case above, it was doing something like "122":match(SOME_PATTERN) and returning 45-. That's right. It returned a string (45-) that was not part of the original string (122).

The problem is that somewhere behind the scenes LuaJ has a LuaString called 122, but it's re-using 45-122 and setting the m_offset at 3 -- hence ignoring the 45-.

Unfortunately, the bug above, stops ignoring the 45- which is why it suddenly reappears.