Make WordPress Core

Ticket #48376: 48376.diff

File 48376.diff, 4.4 KB (added by jorgefilipecosta, 5 years ago)
  • src/wp-includes/kses.php

     
    22092209                'list-style-image',
    22102210        );
    22112211
     2212        /*
     2213         * CSS attributes where we accept gradient data types.
     2214         *
     2215         */
     2216        $css_gradient_data_types = array(
     2217                'background',
     2218                'background-image',
     2219        );
     2220
    22122221        if ( empty( $allowed_attr ) ) {
    22132222                return $css;
    22142223        }
     
    22232232                $css_test_string = $css_item;
    22242233                $found           = false;
    22252234                $url_attr        = false;
     2235                $gradient_attr   = false;
    22262236
    22272237                if ( strpos( $css_item, ':' ) === false ) {
    22282238                        $found = true;
     
    22312241                        $css_selector = trim( $parts[0] );
    22322242
    22332243                        if ( in_array( $css_selector, $allowed_attr, true ) ) {
    2234                                 $found    = true;
    2235                                 $url_attr = in_array( $css_selector, $css_url_data_types, true );
     2244                                $found         = true;
     2245                                $url_attr      = in_array( $css_selector, $css_url_data_types, true );
     2246                                $gradient_attr = in_array( $css_selector, $css_gradient_data_types, true );
    22362247                        }
    22372248                }
    22382249
     
    22612272                        }
    22622273                }
    22632274
     2275                if ( $found && $gradient_attr ) {
     2276                        $css_value = trim( $parts[1] );
     2277                        if ( preg_match( '/^(repeating-)?(linear|radial|conic)-gradient\(([^()]|rgb[a]?\([^()]*\))*\)$/', $css_value ) ) {
     2278                                // Remove the whole `gradient` bit that was matched above from the CSS.
     2279                                $css_test_string = str_replace( $css_value, '', $css_test_string );
     2280                        }
     2281                }
     2282
    22642283                // Remove any CSS containing containing \ ( & } = or comments, except for url() useage checked above.
    22652284                if ( $found && ! preg_match( '%[\\\(&=}]|/\*%', $css_test_string ) ) {
    22662285                        if ( $css != '' ) {
  • tests/phpunit/tests/kses.php

     
    878878                                'css'      => 'columns: 6rem auto;column-count: 4;column-fill: balance;column-gap: 9px;column-rule: thick inset blue;column-span: none;column-width: 120px',
    879879                                'expected' => 'columns: 6rem auto;column-count: 4;column-fill: balance;column-gap: 9px;column-rule: thick inset blue;column-span: none;column-width: 120px',
    880880                        ),
     881                        // Gradients introduced in 5.3.
     882                        array(
     883                                'css'      => 'background: linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
     884                                'expected' => 'background: linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
     885                        ),
     886                        array(
     887                                'css'      => 'background: linear-gradient(135deg,rgba(6,147,227,1) ) (0%,rgb(155,81,224) 100%)',
     888                                'expected' => '',
     889                        ),
     890                        array(
     891                                'css'      => 'background-image: linear-gradient(red,yellow);',
     892                                'expected' => 'background-image: linear-gradient(red,yellow)',
     893                        ),
     894                        array(
     895                                'css'      => 'color: linear-gradient(red,yellow);',
     896                                'expected' => '',
     897                        ),
     898                        array(
     899                                'css'      => 'background-image: linear-gradient(red,yellow); background: prop( red,yellow); width: 100px;',
     900                                'expected' => 'background-image: linear-gradient(red,yellow);width: 100px',
     901                        ),
     902                        array(
     903                                'css'      => 'background: unknown-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
     904                                'expected' => '',
     905                        ),
     906                        array(
     907                                'css'      => 'background: repeating-linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
     908                                'expected' => 'background: repeating-linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
     909                        ),
     910                        array(
     911                                'css'      => 'width: 100px; height: 100px; background: linear-gradient(135deg,rgba(0,208,132,1) 0%,rgba(6,147,227,1) 100%);',
     912                                'expected' => 'width: 100px;height: 100px;background: linear-gradient(135deg,rgba(0,208,132,1) 0%,rgba(6,147,227,1) 100%)',
     913                        ),
     914                        array(
     915                                'css'      => 'background: radial-gradient(#ff0, red, yellow, green, rgba(6,147,227,1), rgb(155,81,224) 90%);',
     916                                'expected' => 'background: radial-gradient(#ff0, red, yellow, green, rgba(6,147,227,1), rgb(155,81,224) 90%)',
     917                        ),
     918                        array(
     919                                'css'      => 'background: radial-gradient(#ff0, red, yellow, green, rgba(6,147,227,1), rgb(155,81,224) 90%);',
     920                                'expected' => 'background: radial-gradient(#ff0, red, yellow, green, rgba(6,147,227,1), rgb(155,81,224) 90%)',
     921                        ),
     922                        array(
     923                                'css'      => 'background: conic-gradient(at 0% 30%, red 10%, yellow 30%, #1e90ff 50%)',
     924                                'expected' => 'background: conic-gradient(at 0% 30%, red 10%, yellow 30%, #1e90ff 50%)',
     925                        ),
     926
    881927                );
    882928        }
    883929