What is the problem?
The sanitizeIP() and prettifyIP() JavaScript functions (in utils.js) throw an error when the argument passed to them is not a string.
This behaviour is different to the PHP version of those functions (in IPUtils) on which they are based.
JavaScript:
mw.util.sanitizeIP( false ); > Uncaught TypeError: ip.replace is not a function mw.util.sanitizeIP( true ); > Uncaught TypeError: ip.replace is not a function mw.util.sanitizeIP( null ); > Uncaught TypeError: ip is null
PHP:
>>> IPUtils::sanitizeIP( false ); => null >>> IPUtils::sanitizeIP( true ); => "1" >>> IPUtils::sanitizeIP( null ); => null
The same is probably true for other data types such as array, etc.
Steps to reproduce problem
- Go to any page on any wiki
- Open the browser console
- Enter: mw.util.sanitizeIP(true)
Expected behavior: Returns something like: "", null, true, "1"
Observed behavior: Throws an error
Environment
Wiki(s): MediaWiki 1.39.0-alpha (a41d695) 13:19, 17 March 2022.