Make WordPress Core

Changeset 47003


Ignore:
Timestamp:
12/21/2019 06:32:45 PM (5 years ago)
Author:
SergeyBiryukov
Message:

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

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/shortcode.js

    r43347 r47003  
    228228
    229229        // Identify a correctly formatted `attrs` object.
    230         } else if ( _.isEqual( _.keys( attrs ), [ 'named', 'numeric' ] ) ) {
    231             this.attrs = attrs;
     230        } else if ( _.difference( _.keys( attrs ), [ 'named', 'numeric' ] ).length === 0 ) {
     231            this.attrs = _.defaults( attrs, this.attrs );
    232232
    233233        // Handle a flat object of attributes.
  • trunk/tests/qunit/wp-includes/js/shortcode.js

    r46586 r47003  
    213213        deepEqual( wp.shortcode.attrs('a="foo" b=\'bar\' c=baz foo "bar" \'baz\''), expected, 'attr parsed numeric attributes');
    214214    });
     215
     216    test( 'string() should accept attrs in any order', function() {
     217        var expected = '[short abc123 foo="bar"]';
     218        var result;
     219
     220        result = wp.shortcode.string({
     221            tag   : 'short',
     222            type  : 'single',
     223            attrs : {
     224                named   : { foo : 'bar' },
     225                numeric : [ 'abc123' ]
     226            }
     227        });
     228        deepEqual( result, expected, 'attributes are accepted in any order' );
     229
     230        result = wp.shortcode.string({
     231            tag   : 'short',
     232            type  : 'single',
     233            attrs : {
     234                numeric : [ 'abc123' ],
     235                named   : { foo : 'bar' }
     236            }
     237        });
     238        deepEqual( result, expected, 'attributes are accepted in any order' );
     239    });
    215240});
Note: See TracChangeset for help on using the changeset viewer.