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

Props yale01, georgestephanis, adamsilverstein, zsusag, mircoraffinetti, SergeyBiryukov.
Fixes #36263.
Built from https://develop.svn.wordpress.org/trunk@47003


git-svn-id: http://core.svn.wordpress.org/trunk@46803 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-12-21 18:34:04 +00:00
parent 27d9bac051
commit 5e8fe89ef5
3 changed files with 4 additions and 4 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

@ -1,2 +1,2 @@
/*! This file is auto-generated */
window.wp=window.wp||{},wp.shortcode={next:function(t,e,n){var s,r,o=wp.shortcode.regexp(t);if(o.lastIndex=n||0,s=o.exec(e))return"["===s[1]&&"]"===s[7]?wp.shortcode.next(t,e,o.lastIndex):(r={index:s.index,content:s[0],shortcode:wp.shortcode.fromMatch(s)},s[1]&&(r.content=r.content.slice(1),r.index++),s[7]&&(r.content=r.content.slice(0,-1)),r)},replace:function(t,e,h){return e.replace(wp.shortcode.regexp(t),function(t,e,n,s,r,o,i,c){if("["===e&&"]"===c)return t;var a=h(wp.shortcode.fromMatch(arguments));return a?e+a+c:t})},string:function(t){return new wp.shortcode(t).string()},regexp:_.memoize(function(t){return new RegExp("\\[(\\[?)("+t+")(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)","g")}),attrs:_.memoize(function(t){var e,n,s={},r=[];for(e=/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g,t=t.replace(/[\u00a0\u200b]/g," ");n=e.exec(t);)n[1]?s[n[1].toLowerCase()]=n[2]:n[3]?s[n[3].toLowerCase()]=n[4]:n[5]?s[n[5].toLowerCase()]=n[6]:n[7]?r.push(n[7]):n[8]?r.push(n[8]):n[9]&&r.push(n[9]);return{named:s,numeric:r}}),fromMatch:function(t){var e;return e=t[4]?"self-closing":t[6]?"closed":"single",new wp.shortcode({tag:t[2],attrs:t[3],type:e,content:t[5]})}},wp.shortcode=_.extend(function(t){_.extend(this,_.pick(t||{},"tag","attrs","type","content"));var e=this.attrs;this.attrs={named:{},numeric:[]},e&&(_.isString(e)?this.attrs=wp.shortcode.attrs(e):_.isEqual(_.keys(e),["named","numeric"])?this.attrs=e:_.each(t.attrs,function(t,e){this.set(e,t)},this))},wp.shortcode),_.extend(wp.shortcode.prototype,{get:function(t){return this.attrs[_.isNumber(t)?"numeric":"named"][t]},set:function(t,e){return this.attrs[_.isNumber(t)?"numeric":"named"][t]=e,this},string:function(){var n="["+this.tag;return _.each(this.attrs.numeric,function(t){/\s/.test(t)?n+=' "'+t+'"':n+=" "+t}),_.each(this.attrs.named,function(t,e){n+=" "+e+'="'+t+'"'}),"single"===this.type?n+"]":"self-closing"===this.type?n+" /]":(n+="]",this.content&&(n+=this.content),n+"[/"+this.tag+"]")}}),wp.html=_.extend(wp.html||{},{attrs:function(t){var e,n;return"/"===t[t.length-1]&&(t=t.slice(0,-1)),e=wp.shortcode.attrs(t),n=e.named,_.each(e.numeric,function(t){/\s/.test(t)||(n[t]="")}),n},string:function(t){var n="<"+t.tag,e=t.content||"";return _.each(t.attrs,function(t,e){n+=" "+e,_.isBoolean(t)&&(t=t?"true":"false"),n+='="'+t+'"'}),t.single?n+" />":(n+=">",(n+=_.isObject(e)?wp.html.string(e):e)+"</"+t.tag+">")}});
window.wp=window.wp||{},wp.shortcode={next:function(t,e,n){var s,r,o=wp.shortcode.regexp(t);if(o.lastIndex=n||0,s=o.exec(e))return"["===s[1]&&"]"===s[7]?wp.shortcode.next(t,e,o.lastIndex):(r={index:s.index,content:s[0],shortcode:wp.shortcode.fromMatch(s)},s[1]&&(r.content=r.content.slice(1),r.index++),s[7]&&(r.content=r.content.slice(0,-1)),r)},replace:function(t,e,h){return e.replace(wp.shortcode.regexp(t),function(t,e,n,s,r,o,i,c){if("["===e&&"]"===c)return t;var a=h(wp.shortcode.fromMatch(arguments));return a?e+a+c:t})},string:function(t){return new wp.shortcode(t).string()},regexp:_.memoize(function(t){return new RegExp("\\[(\\[?)("+t+")(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)","g")}),attrs:_.memoize(function(t){var e,n,s={},r=[];for(e=/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g,t=t.replace(/[\u00a0\u200b]/g," ");n=e.exec(t);)n[1]?s[n[1].toLowerCase()]=n[2]:n[3]?s[n[3].toLowerCase()]=n[4]:n[5]?s[n[5].toLowerCase()]=n[6]:n[7]?r.push(n[7]):n[8]?r.push(n[8]):n[9]&&r.push(n[9]);return{named:s,numeric:r}}),fromMatch:function(t){var e;return e=t[4]?"self-closing":t[6]?"closed":"single",new wp.shortcode({tag:t[2],attrs:t[3],type:e,content:t[5]})}},wp.shortcode=_.extend(function(t){_.extend(this,_.pick(t||{},"tag","attrs","type","content"));var e=this.attrs;this.attrs={named:{},numeric:[]},e&&(_.isString(e)?this.attrs=wp.shortcode.attrs(e):0===_.difference(_.keys(e),["named","numeric"]).length?this.attrs=_.defaults(e,this.attrs):_.each(t.attrs,function(t,e){this.set(e,t)},this))},wp.shortcode),_.extend(wp.shortcode.prototype,{get:function(t){return this.attrs[_.isNumber(t)?"numeric":"named"][t]},set:function(t,e){return this.attrs[_.isNumber(t)?"numeric":"named"][t]=e,this},string:function(){var n="["+this.tag;return _.each(this.attrs.numeric,function(t){/\s/.test(t)?n+=' "'+t+'"':n+=" "+t}),_.each(this.attrs.named,function(t,e){n+=" "+e+'="'+t+'"'}),"single"===this.type?n+"]":"self-closing"===this.type?n+" /]":(n+="]",this.content&&(n+=this.content),n+"[/"+this.tag+"]")}}),wp.html=_.extend(wp.html||{},{attrs:function(t){var e,n;return"/"===t[t.length-1]&&(t=t.slice(0,-1)),e=wp.shortcode.attrs(t),n=e.named,_.each(e.numeric,function(t){/\s/.test(t)||(n[t]="")}),n},string:function(t){var n="<"+t.tag,e=t.content||"";return _.each(t.attrs,function(t,e){n+=" "+e,_.isBoolean(t)&&(t=t?"true":"false"),n+='="'+t+'"'}),t.single?n+" />":(n+=">",(n+=_.isObject(e)?wp.html.string(e):e)+"</"+t.tag+">")}});

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.4-alpha-47002';
$wp_version = '5.4-alpha-47003';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.