Merge "Fix enhanced RC data attribute sanitizing"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.Uri.js
index 835b423..59261cd 100644 (file)
  * @class mw.Uri
  */
 
+/* eslint-disable no-use-before-define */
+
 ( function ( mw, $ ) {
+       var parser, properties;
+
        /**
         * Function that's useful when constructing the URI string -- we frequently encounter the pattern
         * of having to add something to the URI as we go, but only if it's present, and to include a
         * @static
         * @property {Object} parser
         */
-       var parser = {
+       parser = {
                strict: mw.template.get( 'mediawiki.Uri', 'strict.regexp' ).render(),
                loose: mw.template.get( 'mediawiki.Uri', 'loose.regexp' ).render()
-       },
+       };
 
        /**
         * The order here matches the order of captured matches in the `parser` property regexes.
         * @param {string|Function} documentLocation A full url, or function returning one.
         *  If passed a function, the return value may change over time and this will be honoured. (T74334)
         * @member mw
+        * @return {Function} Uri class
         */
        mw.UriRelative = function ( documentLocation ) {
                var getDefaultUri = ( function () {
                 *  override each other (`true`) or automagically convert them to an array (`false`).
                 */
                function Uri( uri, options ) {
-                       var prop,
+                       var prop, hrefCur,
+                               hasOptions = ( options !== undefined ),
                                defaultUri = getDefaultUri();
 
                        options = typeof options === 'object' ? options : { strictMode: !!options };
                                                // Only copy direct properties, not inherited ones
                                                if ( uri.hasOwnProperty( prop ) ) {
                                                        // Deep copy object properties
-                                                       if ( $.isArray( uri[ prop ] ) || $.isPlainObject( uri[ prop ] ) ) {
+                                                       if ( Array.isArray( uri[ prop ] ) || $.isPlainObject( uri[ prop ] ) ) {
                                                                this[ prop ] = $.extend( true, {}, uri[ prop ] );
                                                        } else {
                                                                this[ prop ] = uri[ prop ];
                                                this.query = {};
                                        }
                                }
+                       } else if ( hasOptions ) {
+                               // We didn't get a URI in the constructor, but we got options.
+                               hrefCur = typeof documentLocation === 'string' ? documentLocation : documentLocation();
+                               this.parse( hrefCur, options );
                        } else {
-                               // If we didn't get a URI in the constructor, use the default one.
+                               // We didn't get a URI or options in the constructor, use the default instance.
                                return defaultUri.clone();
                        }
 
                                                                        q[ k ] = [ q[ k ] ];
                                                                }
                                                                // Add to the array
-                                                               if ( $.isArray( q[ k ] ) ) {
+                                                               if ( Array.isArray( q[ k ] ) ) {
                                                                        q[ k ].push( v );
                                                                }
                                                        }
                                var args = [];
                                $.each( this.query, function ( key, val ) {
                                        var k = Uri.encode( key ),
-                                               vals = $.isArray( val ) ? val : [ val ];
+                                               vals = Array.isArray( val ) ? val : [ val ];
                                        $.each( vals, function ( i, v ) {
                                                if ( v === null ) {
                                                        args.push( k );