Index: trunk/phase3/includes/Linker.php |
— | — | @@ -257,11 +257,9 @@ |
258 | 258 | |
259 | 259 | # Finally, merge the custom attribs with the default ones, and iterate |
260 | 260 | # over that, deleting all "false" attributes. |
261 | | - if( !empty( $attribs['class'] ) and !empty( $defaults['class'] ) ) { |
262 | | - $attribs['class'] .= ' '.$defaults['class']; |
263 | | - } |
264 | 261 | $ret = array(); |
265 | | - foreach( array_merge( $defaults, $attribs ) as $key => $val ) { |
| 262 | + $merged = Sanitizer::mergeAttributes( $defaults, $attribs ); |
| 263 | + foreach( $merged as $key => $val ) { |
266 | 264 | # A false value suppresses the attribute, and we don't want the |
267 | 265 | # href attribute to be overridden. |
268 | 266 | if( $key != 'href' and $val !== false ) { |
Index: trunk/phase3/includes/Sanitizer.php |
— | — | @@ -627,10 +627,9 @@ |
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
631 | | - * Merge two sets of HTML attributes. |
632 | | - * Conflicting items in the second set will override those |
633 | | - * in the first, except for 'class' attributes which will be |
634 | | - * combined. |
| 631 | + * Merge two sets of HTML attributes. Conflicting items in the second set |
| 632 | + * will override those in the first, except for 'class' attributes which |
| 633 | + * will be combined (if they're both strings). |
635 | 634 | * |
636 | 635 | * @todo implement merging for other attributes such as style |
637 | 636 | * @param array $a |
— | — | @@ -639,16 +638,12 @@ |
640 | 639 | */ |
641 | 640 | static function mergeAttributes( $a, $b ) { |
642 | 641 | $out = array_merge( $a, $b ); |
643 | | - if( isset( $a['class'] ) |
644 | | - && isset( $b['class'] ) |
645 | | - && $a['class'] !== $b['class'] ) { |
646 | | - |
647 | | - $out['class'] = implode( ' ', |
648 | | - array_unique( |
649 | | - preg_split( '/\s+/', |
650 | | - $a['class'] . ' ' . $b['class'], |
651 | | - -1, |
652 | | - PREG_SPLIT_NO_EMPTY ) ) ); |
| 642 | + if( isset( $a['class'] ) && isset( $b['class'] ) |
| 643 | + && is_string( $a['class'] ) && is_string( $b['class'] ) |
| 644 | + && $a['class'] !== $b['class'] ) { |
| 645 | + $classes = preg_split( '/\s+/', "{$a['class']} {$b['class']}", |
| 646 | + -1, PREG_SPLIT_NO_EMPTY ); |
| 647 | + $out['class'] = implode( ' ', array_unique( $classes ) ); |
653 | 648 | } |
654 | 649 | return $out; |
655 | 650 | } |