Page MenuHomePhabricator

Create IP utilities for sanitizing and prettifying IPs via js
Closed, ResolvedPublic3 Estimated Story Points

Description

In IPUtils.php there are the sanitizeIP and prettifyIP functions which do not have equivalents in js. It would be useful for IP Info (specifically for T299382: Error in popup when trying to view info for IPv6 edits in Recent Changes enhanced view) if these did exist in the js.

AC

  • Add sanitizeIP and prettifyIP functions to resources/src/mediawiki.util/util.js which already has some IP utility functions
  • Write unit tests for the new functions

Notes

Documentation on testing in JavaScript: https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing

Event Timeline

Tchanders updated the task description. (Show Details)

Change 767049 had a related patch set uploaded (by TsepoThoabala; author: TsepoThoabala):

[mediawiki/core@master] WIP: Create IP utilities for sanitizing and prettifying IPs via js

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

Change 767049 merged by jenkins-bot:

[mediawiki/core@master] Create IP utilities for sanitizing and prettifying IPs via js

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

dom_walden subscribed.

Actually, I would like to test this in isolation (I assume I can via the browser console). Moving back into QA.

I assume we want these new JavaScript functions to behave the same as the PHP functions in IPUtils on which they are based. Therefore, I compared the output of these JavaScript functions (when run in Firefox's console) with the PHP functions for the same input.

I took test data from the IPUtils unit tests (P22787) and randomly generated some more (P22786).

There were no differences in output from either function when compared to PHP, with the exception of non-string inputs which threw an error in JavaScript. I raised this separately T304082.

EDIT Because I understand we had some problems with ES5 vs. ES6, so I repeated some of the above testing with IE11 (which apparently only has partial ES6 support). It was also fine.

Test environment: https://en.wikipedia.beta.wmflabs.org MediaWiki 1.39.0-alpha (a41d695) 13:19, 17 March 2022.
Test browser: Firefox 91. IE11.

Change 793084 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] mediawiki.util: Make internal repeatString() function non-public

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

Change 793084 merged by jenkins-bot:

[mediawiki/core@master] mediawiki.util: Make internal repeatString() function non-public

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