Make WordPress Core

Ticket #6602: bug6602.patch

File bug6602.patch, 3.0 KB (added by schiller, 17 years ago)

Updated patch to take first attribute and ignore later duplicate attributes (per Sam Ruby's comment)

  • kses.php

     
    531531 * input. It will add quotes around attribute values that don't have any quotes
    532532 * or apostrophes around them, to make it easier to produce HTML code that will
    533533 * conform to W3C's HTML specification. It will also remove bad URL protocols
    534  * from attribute values.
     534 * from attribute values.  It also reduces duplicate attributes by using the
     535 * attribute defined first (foo='bar' foo='baz' will result in foo='bar').
    535536 *
    536537 * @since 1.0.0
    537538 *
     
    574575                                        {
    575576                                        $working = 1;
    576577                                        $mode = 0;
    577                                         $attrarr[] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
     578                                        if(FALSE === array_key_exists($attrname, $attrarr)) {
     579                                                $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
     580                                        }
    578581                                        $attr = preg_replace('/^\s+/', '', $attr);
    579582                                }
    580583
     
    587590                                        {
    588591                                        $thisval = wp_kses_bad_protocol($match[1], $allowed_protocols);
    589592
    590                                         $attrarr[] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
     593                                        if(FALSE === array_key_exists($attrname, $attrarr)) {
     594                                                $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
     595                                        }
    591596                                        $working = 1;
    592597                                        $mode = 0;
    593598                                        $attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
     
    599604                                        {
    600605                                        $thisval = wp_kses_bad_protocol($match[1], $allowed_protocols);
    601606
    602                                         $attrarr[] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n');
     607                                        if(FALSE === array_key_exists($attrname, $attrarr)) {
     608                                                $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n');
     609                                        }
    603610                                        $working = 1;
    604611                                        $mode = 0;
    605612                                        $attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
     
    611618                                        {
    612619                                        $thisval = wp_kses_bad_protocol($match[1], $allowed_protocols);
    613620
    614                                         $attrarr[] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
     621                                        if(FALSE === array_key_exists($attrname, $attrarr)) {
     622                                                $attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
     623                                        }
    615624                                        # We add quotes to conform to W3C's HTML spec.
    616625                                        $working = 1;
    617626                                        $mode = 0;
     
    628637                }
    629638        } # while
    630639
    631         if ($mode == 1)
     640        if ($mode == 1 && FALSE === array_key_exists($attrname, $attrarr)) {
    632641                # special case, for when the attribute list ends with a valueless
    633642                # attribute like "selected"
    634                 $attrarr[] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
     643                $attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
    635644
    636645        return $attrarr;
    637646}