Liangent has uploaded a new change for review.

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

Change subject: LanguageConverter fix of empty and numeric strings
......................................................................

LanguageConverter fix of empty and numeric strings

Bug: 49072
Bug: 46634
Bug: 51551
Change-Id: I2c88f1cf7c0014bebf5c798916b660b334a0b78b
---
M languages/LanguageConverter.php
M tests/parser/parserTests.txt
2 files changed, 44 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/17/131717/1

diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php
index 57e73da..4ab4e3f 100644
--- a/languages/LanguageConverter.php
+++ b/languages/LanguageConverter.php
@@ -1004,7 +1004,7 @@
                if ( $recursive ) {
                        foreach ( $sublinks as $link ) {
                                $s = $this->parseCachedTable( $code, $link, 
$recursive );
-                               $ret = array_merge( $ret, $s );
+                               $ret = $s + $ret;
                        }
                }
 
@@ -1260,18 +1260,20 @@
                        $to = trim( $v[1] );
                        $v = trim( $v[0] );
                        $u = explode( '=>', $v, 2 );
-                       // if $to is empty, strtr() could return a wrong result
-                       if ( count( $u ) == 1 && $to && in_array( $v, $variants 
) ) {
+                       // if $to is empty (which is also used as $from in 
bidtable),
+                       // strtr() could return a wrong result.
+                       if ( count( $u ) == 1 && $to !== '' && in_array( $v, 
$variants ) ) {
                                $bidtable[$v] = $to;
                        } elseif ( count( $u ) == 2 ) {
                                $from = trim( $u[0] );
                                $v = trim( $u[1] );
+                               // if $from is empty, strtr() could return a 
wrong result.
                                if ( array_key_exists( $v, $unidtable )
                                        && !is_array( $unidtable[$v] )
-                                       && $to
+                                       && $from !== ''
                                        && in_array( $v, $variants ) ) {
                                        $unidtable[$v] = array( $from => $to );
-                               } elseif ( $to && in_array( $v, $variants ) ) {
+                               } elseif ( $from !== '' && in_array( $v, 
$variants ) ) {
                                        $unidtable[$v][$from] = $to;
                                }
                        }
@@ -1325,17 +1327,17 @@
                        // display current variant in bidirectional array
                        $disp = $this->getTextInBidtable( $variant );
                        // or display current variant in fallbacks
-                       if ( !$disp ) {
+                       if ( $disp === false ) {
                                $disp = $this->getTextInBidtable(
                                                
$this->mConverter->getVariantFallbacks( $variant ) );
                        }
                        // or display current variant in unidirectional array
-                       if ( !$disp && array_key_exists( $variant, $unidtable ) 
) {
+                       if ( $disp === false && array_key_exists( $variant, 
$unidtable ) ) {
                                $disp = array_values( $unidtable[$variant] );
                                $disp = $disp[0];
                        }
                        // or display frist text under disable manual convert
-                       if ( !$disp && 
$this->mConverter->mManualLevel[$variant] == 'disable' ) {
+                       if ( $disp === false && 
$this->mConverter->mManualLevel[$variant] == 'disable' ) {
                                if ( count( $bidtable ) > 0 ) {
                                        $disp = array_values( $bidtable );
                                        $disp = $disp[0];
@@ -1430,7 +1432,7 @@
                                && isset( $unidtable[$v] )
                        ) {
                                if ( isset( $this->mConvTable[$v] ) ) {
-                                       $this->mConvTable[$v] = array_merge( 
$this->mConvTable[$v], $unidtable[$v] );
+                                       $this->mConvTable[$v] = $unidtable[$v] 
+ $this->mConvTable[$v];
                                } else {
                                        $this->mConvTable[$v] = $unidtable[$v];
                                }
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index e8e71b8..4dc16b0 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -15653,6 +15653,39 @@
 !! end
 
 !! test
+Strings evaluating false shouldn't be ignored by Language converter (bug 49072)
+!! options
+language=zh variant=zh-cn
+!! input
+-{zh-cn:0;zh-sg:1;zh-tw:2;zh-hk:3}-
+!! result
+<p>0
+</p>
+!! end
+
+!! test
+Conversion rules from [numeric-only string] to [something else] (bug 46634)
+!! options
+language=zh variant=zh-cn
+!! input
+-{H|0=>zh-hans:A}--{H|0=>zh-cn:B}-012
+!! result
+<p>B12
+</p>
+!! end
+
+!! test
+Unidirectional converter rule entries with an empty "from" string should be 
ignored (bug 51551)
+!! options
+language=zh variant=zh-cn
+!! input
+-{H|=>zh-cn:foo;}-foobar
+!! result
+<p>foobar
+</p>
+!! end
+
+!! test
 Nested using of manual convert syntax
 !! options
 language=zh variant=zh-hk

-- 
To view, visit https://gerrit.wikimedia.org/r/131717
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2c88f1cf7c0014bebf5c798916b660b334a0b78b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Liangent <liang...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to