WordPress.org

Make WordPress Core

Ticket #44988: 44988-broken.patch

File 44988-broken.patch, 2.2 KB (added by ayeshrajans, 2 years ago)

This breaks tests: https://travis-ci.org/Ayesh/wordpress-develop/builds/434524930

  • src/wp-includes/formatting.php

    diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
    index 0e175f24e7..2d37d7f992 100644
    a b function sanitize_sql_orderby( $orderby ) { 
    20582058/**
    20592059 * Sanitizes an HTML classname to ensure it only contains valid characters.
    20602060 *
    2061  * Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty
    2062  * string then it will return the alternative value supplied.
     2061 * Strips the string down to A-Z,a-z,0-9,_,- and attempts to further adhere to
     2062 * the specification (@see https://www.w3.org/TR/CSS22/syndata.html#characters).
     2063 * If this results in an empty string then it will return the alternative
     2064 * value supplied.
    20632065 *
    20642066 * @todo Expand to support the full range of CDATA that a class attribute can contain.
    20652067 *
    function sanitize_html_class( $class, $fallback = '' ) { 
    20772079        //Limit to A-Z,a-z,0-9,_,-
    20782080        $sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized );
    20792081
     2082        //Replace digits, hyphen and double hyphen at begining of class name because
     2083        //they are not allowed as per spec.
     2084        $sanitized = preg_replace( array(
     2085                '/^[0-9]/',
     2086                '/^(-[0-9])|^(--)/',
     2087        ), array(
     2088                '_',
     2089                '__',
     2090        ), $sanitized);
     2091
    20802092        if ( '' == $sanitized && $fallback ) {
    20812093                return sanitize_html_class( $fallback );
    20822094        }
  • new file tests/phpunit/tests/formatting/SanitizeClassName.php

    diff --git a/tests/phpunit/tests/formatting/SanitizeClassName.php b/tests/phpunit/tests/formatting/SanitizeClassName.php
    new file mode 100644
    index 0000000000..970059bba9
    - +  
     1<?php
     2
     3/**
     4 * @group formatting
     5 */
     6class Tests_Formatting_SanitizeClassName extends WP_UnitTestCase {
     7        function test_html_class_name() {
     8                $tests = array(
     9                        'space separated' => 'spaceseparated',
     10                        'CASE_PRESERVED' => 'CASE_PRESERVED',
     11                        '$invalid^chars' => 'invalidchars',
     12                        '0starts-with-integer' => '_starts-with-integer',
     13                        '-starts-with--' => '-starts-with--', // this is allowed because the rule is /^-[0-9]/
     14                        '-0starts-with-integer' => '__starts-with-integer',
     15                        '--starts-with---' => '__starts-with---',
     16                );
     17                foreach ( $tests as $key => $value ) {
     18                        $this->assertEquals( $value, sanitize_html_class( $key ) );
     19                }
     20        }
     21}