mediawiki.jqueryMsg: Don't duplicate link contents if parse() is called multiple...
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 4 Nov 2015 23:43:18 +0000 (00:43 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 5 Nov 2015 15:33:47 +0000 (16:33 +0100)
    mw.messages.set( 'foo', '[$1 Link]' );
    var msg = mw.message( 'foo', $( '<a>' ).attr( 'href', 'http://example.com/' ) );
    msg.parse(); msg.parse(); msg.parse();
    $( 'body ').append( msg.parse() ); // The link now says "LinkLinkLinkLink"

Change-Id: Id170b328164527320326178f24f56c5077cd50ab

resources/src/mediawiki/mediawiki.jqueryMsg.js
tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js

index 2e89f6b..bf0884b 100644 (file)
                                        $el.attr( 'href', textify( arg ) );
                                }
                        }
-                       return appendWithoutParsing( $el, contents );
+                       return appendWithoutParsing( $el.empty(), contents );
                },
 
                /**
index 24528bb..f65ff16 100644 (file)
                assert.equal( logSpy.callCount, 2, 'mw.log.warn calls' );
        } );
 
-       QUnit.test( 'Integration', 4, function ( assert ) {
-               var expected, logSpy;
+       QUnit.test( 'Integration', 5, function ( assert ) {
+               var expected, logSpy, msg;
 
                expected = '<b><a title="Bold" href="/wiki/Bold">Bold</a>!</b>';
                mw.messages.set( 'integration-test', '<b>[[Bold]]!</b>' );
                        expected,
                        'jQuery plugin $.fn.msg() works correctly'
                );
+
+               mw.messages.set( 'integration-test-extlink', '[$1 Link]' );
+               msg = mw.message(
+                       'integration-test-extlink',
+                       $( '<a>' ).attr( 'href', 'http://example.com/' )
+               );
+               msg.parse(); // Not a no-op
+               assert.equal(
+                       msg.parse(),
+                       '<a href="http://example.com/">Link</a>',
+                       'Calling .parse() multiple times does not duplicate link contents'
+               );
        } );
 
 }( mediaWiki, jQuery ) );