diff --git a/src/js/_enqueues/wp/shortcode.js b/src/js/_enqueues/wp/shortcode.js index 8f02273ba7..bf3e1e21a0 100644 --- a/src/js/_enqueues/wp/shortcode.js +++ b/src/js/_enqueues/wp/shortcode.js @@ -227,8 +227,8 @@ window.wp = window.wp || {}; this.attrs = wp.shortcode.attrs( attrs ); // Identify a correctly formatted `attrs` object. - } else if ( _.isEqual( _.keys( attrs ), [ 'named', 'numeric' ] ) ) { - this.attrs = attrs; + } else if ( _.difference( _.keys( attrs ), [ 'named', 'numeric' ] ).length === 0 ) { + this.attrs = _.defaults( attrs, this.attrs ); // Handle a flat object of attributes. } else { diff --git a/tests/qunit/wp-includes/js/shortcode.js b/tests/qunit/wp-includes/js/shortcode.js index 2fd3c54d4c..c7e269f955 100644 --- a/tests/qunit/wp-includes/js/shortcode.js +++ b/tests/qunit/wp-includes/js/shortcode.js @@ -212,4 +212,29 @@ jQuery( function() { deepEqual( wp.shortcode.attrs('a="foo" b=\'bar\' c=baz foo "bar" \'baz\''), expected, 'attr parsed numeric attributes'); }); + + test( 'string() should accept attrs in any order', function() { + var expected = '[short abc123 foo="bar"]'; + var result; + + result = wp.shortcode.string({ + tag : 'short', + type : 'single', + attrs : { + named : { foo : 'bar' }, + numeric : [ 'abc123' ] + } + }); + deepEqual( result, expected, 'attributes are accepted in any order' ); + + result = wp.shortcode.string({ + tag : 'short', + type : 'single', + attrs : { + numeric : [ 'abc123' ], + named : { foo : 'bar' } + } + }); + deepEqual( result, expected, 'attributes are accepted in any order' ); + }); });