Make WordPress Core


Ignore:
Timestamp:
10/08/2015 03:11:59 AM (10 years ago)
Author:
johnbillion
Message:

Abstract the shortcode attribute parsing regex into its own function, update the JavaScript counterpart, and introduce a test to ensure they do not diverge again.

Fixes #34191
Props miqrogroove, johnbillion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/shortcodes.php

    r34868 r34933  
    452452
    453453/**
     454 * Retrieve the shortcode attributes regex.
     455 *
     456 * @since 4.4.0
     457 *
     458 * @return string The shortcode attribute regular expression
     459 */
     460function get_shortcode_atts_regex() {
     461    return '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
     462}
     463
     464/**
    454465 * Retrieve all attributes from the shortcodes tag.
    455466 *
     
    468479function shortcode_parse_atts($text) {
    469480    $atts = array();
    470     $pattern = '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
     481    $pattern = get_shortcode_atts_regex();
    471482    $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
    472483    if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
Note: See TracChangeset for help on using the changeset viewer.