gnosygnu / xowa

xowa offline wiki application
Other
374 stars 41 forks source link

Luaj: Handle % at end of replacement string (ArrayIndexOutOfBoundsException) #571

Closed desb42 closed 5 years ago

desb42 commented 5 years ago

I managed to get this error

java.lang.ArrayIndexOutOfBoundsException: 4

when I was playing around with SHORTDESC

I have been able to reproduce this in xowa-gui The Lua code

function p.test(frame)
    text = 'episodes|{}'
    subst = '.07%'
    return text:gsub("{}", subst)
end

calling this with

{{#invoke:test|test}}

will provoke the problem

I think it is to do with the trailing percent sign%

BTW the actual logic is in en.wikipedia.org/wiki/Module:Television_episode_short_description and the page that causes this (for me) is en.wikipedia.org/wiki/.07%

gnosygnu commented 5 years ago

Nice catch. This occurred when % is at the end of the replacement string (% is a special Lua escape string)

Fixed it in the commit above. Thanks!