Shortcodes: Make sure wp.shortcode.string() accepts the attrs array keys in any order.

Props yale01, georgestephanis, adamsilverstein, zsusag, mircoraffinetti, SergeyBiryukov.
Fixes #36263.

git-svn-id: https://develop.svn.wordpress.org/trunk@47003 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-12-21 18:32:45 +00:00
parent 939fbfa7d3
commit 7abc076e13
2 changed files with 27 additions and 2 deletions

View File

@ -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 {

View File

@ -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' );
});
});