Page MenuHomePhabricator

Arrays extension cannot parse certain numbers
Open, Needs TriagePublic

Description

The Arrays extension (version 2.2.0) cannot parse certain numbers (1, 2, 3, 0) under certain condition. These number changed to "Array" on output if a custom pattern is used.

Input:

{{#arraydefine:places|1234567890; 2WE340; 654453562|;}}
{{#arrayprint:places||@R|<nowiki/>
* [[@R]]}}
{{#arrayprint:places}}

Output:

  - ArrayArrayArray456789Array
  - ArrayWEArray4Array
  - 65445Array56Array

1234567890, 2WE340, 654453562

Details

Related Changes in Gerrit:

Event Timeline

Ammarpad renamed this task from mediawiki array cannot parse certain numbers to Arrays extension cannot parse certain numbers.Feb 13 2020, 11:15 AM

This works as expected on a wiki with Arrays 2.1.0; unfortunately I don't have any wikis to hand with Arrays 2.2.0 to test on.

Same problem here:

{{#arraydefine:test|-1,-2,1,2,3|,}}
{{#arrayprint:test|<br/>|@@@@|Test: @@@@}}

turns into:

Test: -Array
Test: -Array
Test: Array
Test: Array
Test: Array

I found a Notice:

Notice: Array to string conversion in PATH/htdocs/mediawiki-1.34.1/extensions/Arrays/ExtArrays.php on line 1220 Notice: Array to string conversion in PATH/htdocs/mediawiki-1.34.1/extensions/Arrays/ExtArrays.php on line 1220

Looking into the code, I realized that this won't be called in legacy mode. I set the variable, and now it works for me.

With $egArraysCompatibilityMode set to true, the extension will make use of $egArraysExpansionEscapeTemplates, which is an associative array that allows to escape certain chars that would have, otherwise, special meaning (detailed info).

In that case, since $egArraysExpansionEscapeTemplates won't be null, then, the final string will be escaped, by making use of the associative array contained in that var.
The code is:

 	public static function escapeForExpansion( $string ) {
		global $egArraysExpansionEscapeTemplates;

		if ( $egArraysExpansionEscapeTemplates === null ) {
			return $string;
		}

		$string = strtr(
			$string,
			$egArraysExpansionEscapeTemplates
		);

		return $string;
 	}

The function strtr should be able to take both a string or an array there, as the second arg. That's the part I can't figure out. For some reason, instead of parsing the second argument correctly, as an array, it's simply implicitly converting it to string. The string representation of an array is "Array", hence why it appears when calling the parser function.
Another thought, since it's replacing numbers with "Array" I would say that, for some reason, it is receiving a non-associative array (numbered keys), whose values are the array entries (key => value) and that they, alone, represent a one-item array. Hence why the numbers are being replaced with "Array", because strtr seems to be receiving something like [ [ '|' => '{{!}}' ], /* etc */ ]. This would explain the rendered output. But after checking the code, it seems $egArraysExpansionEscapeTemplates is well defined. As you can see, though, there are 4 entries; that's why only 0, 1, 2 and 3 get replaced with "Array".
Maybe someone is able to understand better what's going on. I'm from the same wiki as Dinoguy1000, so we have the older version.

Can you try again with the master version of the Arrays extension? This is probably broken because the global default value has been broken for some time in v2.2: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Arrays/+/6a47eac735e7cd9c16b445453f960e6b057845ae

Having the same problem here. Cross posting this from https://www.mediawiki.org/wiki/Extension_talk:Arrays . It's not a fix, but at least a rather clunky workaround, without the negatives of compatability mode. Only negative is that when you sort the array, 1, 2, and 3 will sort at the end, rather than the beginning.

In my case, {{{Bar}}} is a CSV string that I turn into an array.

{{#arraydefine:Foo|{{#replace:{{#replace:{{#replace:{{{Bar}}}|1|①}}|2|②}}|3|③}} }}

Then later:

{{#arrayprint:Foo|<br/>|@@@@ |{{#vardefine:val|{{#replace:{{#replace:{{#replace:@@@@|①|1}}|②|2}}|③|3}} }} ... }}

As more wikis are updating to MW 1.34+, this is impacting more people. See for example https://www.mediawiki.org/wiki/Topic:Vuij4e8ea5ydavbn. Would be nice to see this fixed in a new point release of the extension.

Can you try again with the master version of the Arrays extension? This is probably broken because the global default value has been broken for some time in v2.2: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Arrays/+/6a47eac735e7cd9c16b445453f960e6b057845ae

Confirmed this fix. It should be backported to REL1_* branches.

As more wikis are updating to MW 1.34+, this is impacting more people. See for example https://www.mediawiki.org/wiki/Topic:Vuij4e8ea5ydavbn. Would be nice to see this fixed in a new point release of the extension.

This was actually fixed on 2019-Sep-28. It does need to be back-ported, though.

Change 646869 had a related patch set uploaded (by MarkAHershberger; owner: MarkAHershberger):
[mediawiki/extensions/Arrays@master] Bump version and tag bug

https://gerrit.wikimedia.org/r/646869

Change 646869 merged by MarkAHershberger:
[mediawiki/extensions/Arrays@master] Bump version and tag bug

https://gerrit.wikimedia.org/r/646869