(bug 42513) mediawiki.Uri: Fix parsing of URIs with @ in path.
authorTyler Anthony Romeo <tylerromeo@gmail.com>
Fri, 18 Jan 2013 17:46:02 +0000 (12:46 -0500)
committerTimo Tijhof <ttijhof@wikimedia.org>
Sat, 19 Jan 2013 18:20:46 +0000 (19:20 +0100)
The regexes for URI parsing in mediawiki.Uri did not make sure
there were no slashes (/), question marks (?) or hashes (#) in
the username or password of the URI. As a result an @ symbol
later on in the url messed up the result.

This commit fixes the regexes so that URIs with an @ symbol in
the path, query, or fragment don't get interpreted as having
a username when they actually don't.

Change-Id: I4954bfd3750d5c990e91cc0dc8a175225ccbad1e

resources/mediawiki/mediawiki.Uri.js
tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js

index 2cb4c3a..643e5c3 100644 (file)
@@ -76,8 +76,8 @@
 
        // Regular expressions to parse many common URIs.
        var parser = {
-               strict: /^(?:([^:\/?#]+):)?(?:\/\/(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)?((?:[^?#\/]*\/)*[^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
-               loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?((?:\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?[^?#\/]*)(?:\?([^#]*))?(?:#(.*))?/
+               strict: /^(?:([^:\/?#]+):)?(?:\/\/(?:(?:([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?([^:\/?#]*)(?::(\d*))?)?((?:[^?#\/]*\/)*[^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
+               loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?(?:(?:([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?([^:\/?#]*)(?::(\d*))?((?:\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?[^?#\/]*)(?:\?([^#]*))?(?:#(.*))?/
        },
 
        // The order here matches the order of captured matches in the above parser regexes.
index 7fc7453..9eb2efc 100644 (file)
                assert.ok( relativePath.indexOf( uri.fragment ) >= 0, 'fragement in relative path' );
        } );
 
+       QUnit.test( 'Parse a uri with an @ symbol in the path and query', 1, function ( assert ) {
+               var uri = new mw.Uri( 'http://www.example.com/test@test?x=@uri&y@=uri&z@=@' );
+
+               assert.deepEqual(
+                       {
+                               protocol: uri.protocol,
+                               user: uri.user,
+                               password: uri.password,
+                               host: uri.host,
+                               port: uri.port,
+                               path: uri.path,
+                               query: uri.query,
+                               fragment: uri.fragment,
+                               queryString: uri.getQueryString()
+                       },
+                       {
+                               protocol: 'http',
+                               user: undefined,
+                               password: undefined,
+                               host: 'www.example.com',
+                               port: undefined,
+                               path: '/test@test',
+                               query: { x: '@uri', 'y@': 'uri', 'z@': '@' },
+                               fragment: undefined,
+                               queryString: 'x=%40uri&y%40=uri&z%40=%40'
+                       },
+                       'basic object properties'
+               );
+       } );
+
        QUnit.test( 'Handle protocol-relative URLs', 5, function ( assert ) {
                var UriRel, uri;