gnosygnu / xowa

xowa offline wiki application
Other
375 stars 41 forks source link

a curious matter of space #471

Open desb42 opened 5 years ago

desb42 commented 5 years ago

this was triggered by looking at en.wikipedia.org/wiki/Template:Dubious There is a line of wikitext

:;{{Tlx|Dubious |{{var|Talk section name}} |4=date={{CURRENTMONTHNAME}} {{CURRENTYEAR}}}}
               ^

Note the indicated space character In xowa this is: dubious1

In mediawiki dubious2

Note the space between the end of dubious and the pipe character |

I always thought that whitespace was trimmed from the beggining and end of 'pipe' arguments On other experiments that I will not go into here, it seems that there is a difference between positional arguments and keyed arguments. A difference is that mediawiki 'trims' the keyed arguments in a different way to the positional ones

Further experiments show some other differences This wikitext

:;{{Tlx|    Dubious      |   {{var|Talk section name}}    |4=date={{CURRENTMONTHNAME}} {{CURRENTYEAR}}}}

:;{{Tlx|Dubious 
|{{var|Talk section name}} |3=reason={{var|Summary of problem}} |4=date={{CURRENTMONTHNAME}} {{CURRENTYEAR}}}}

[[Template:Dubious
|Dubious ]]

Produces in xowa dubious3

In mediawiki dubious4

Note the failures

gnosygnu commented 5 years ago

Thanks for the write-up. Most of the logic for white-space trimming is here (trim start is below, but trim end is very similar): https://github.com/gnosygnu/xowa/blob/master/400_xowa/src/gplx/xowa/parsers/tmpls/Arg_bldr.java#L152-L154 . The code is as follows

case Xop_arg_wkr_.Typ_prm : trim = arg_idx == 0; break;
case Xop_arg_wkr_.Typ_tmpl: trim = key_exists || arg_idx == 0; break;
case Xop_arg_wkr_.Typ_lnki: trim = cur_itm_is_key || !key_exists; break;    // NOTE (this comment was wrong): trim if " a=b"; skip if "a= b" or " a"

First, about the different types

So, that said, the logic is as follows

Now, that said, this logic was derived by testing various inputs. I didn't check MediaWiki code at the time, and I suspect the rules above are wrong or have changed.

This may explain the divergence above. Let me look at this some more as well