jenkins-bot has submitted this change and it was merged.

Change subject: Fix ustring errors
......................................................................


Fix ustring errors

* mw.ustring.sub( '', 1 ) errors in LuaStandalone
* Default value for ustring.maxStringLength and ustring.maxPatternLength
  should be infinity, not nil
* mw.ustring.find() returns one value instead of two in "plain" mode.

Change-Id: I5e65c4ec3a05f0e6930ce7ab7fd4ac72bea95e7f
---
M engines/LuaCommon/UstringLibrary.php
M engines/LuaCommon/lualib/ustring/ustring.lua
M tests/engines/LuaCommon/UstringLibraryTests.lua
3 files changed, 17 insertions(+), 4 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/engines/LuaCommon/UstringLibrary.php 
b/engines/LuaCommon/UstringLibrary.php
index d6661b3..5821a2d 100644
--- a/engines/LuaCommon/UstringLibrary.php
+++ b/engines/LuaCommon/UstringLibrary.php
@@ -459,7 +459,11 @@
 
                if ( $plain ) {
                        $ret = mb_strpos( $s, $pattern, 0, 'UTF-8' );
-                       return array( ( $ret === false ) ? null : $ret + $init 
);
+                       if ( $ret === false ) {
+                               return array( null );
+                       } else {
+                               return array( $ret + $init, $ret + $init + 
mb_strlen( $pattern ) - 1 );
+                       }
                }
 
                list( $re, $capt ) = $this->patternToRegex( $pattern );
diff --git a/engines/LuaCommon/lualib/ustring/ustring.lua 
b/engines/LuaCommon/lualib/ustring/ustring.lua
index 2c95db4..4aa299f 100644
--- a/engines/LuaCommon/lualib/ustring/ustring.lua
+++ b/engines/LuaCommon/lualib/ustring/ustring.lua
@@ -15,8 +15,8 @@
 
 ---- Configuration ----
 -- To limit the length of strings or patterns processed, set these
-ustring.maxStringLength = inf
-ustring.maxPatternLength = inf
+ustring.maxStringLength = math.huge
+ustring.maxPatternLength = math.huge
 
 ---- Utility functions ----
 
@@ -137,7 +137,8 @@
                i = i + 1 + trail
        end
 
-       -- One past the end
+       -- Two past the end (for sub with empty string)
+       ret.bytepos[#ret.bytepos + 1] = l + 1
        ret.bytepos[#ret.bytepos + 1] = l + 1
 
        return ret
diff --git a/tests/engines/LuaCommon/UstringLibraryTests.lua 
b/tests/engines/LuaCommon/UstringLibraryTests.lua
index 7a6e201..d968b58 100644
--- a/tests/engines/LuaCommon/UstringLibraryTests.lua
+++ b/tests/engines/LuaCommon/UstringLibraryTests.lua
@@ -139,6 +139,10 @@
          args = { str1, 5, 5 },
          expect = { "\224\160\128" }
        },
+       { name = 'sub: empty string', func = mw.ustring.sub,
+         args = { '', 5 },
+         expect = { "" }
+       },
 
        { name = 'upper: basic test', func = mw.ustring.upper,
          args = { "fóó?" },
@@ -277,6 +281,10 @@
          args = { "¡foo¡ ¡bar¡ baz", '¡.-¡' },
          expect = { 1, 5 }
        },
+       { name = 'find: plain', func = mw.ustring.find,
+         args = { "¡a¡ ¡.¡", '¡.¡', 1, true },
+         expect = { 5, 7 }
+       },
 
        { name = 'find: capture (1)', func = mw.ustring.find,
          args = { "bar ¡foo bar", '(¡foo)' },

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5e65c4ec3a05f0e6930ce7ab7fd4ac72bea95e7f
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to