Make WordPress Core

Ticket #19922: 19922.patch

File 19922.patch, 1.2 KB (added by kurtpayne, 13 years ago)

Encoding only non-printable ASCII

  • class-http.php

     
    15401540                if ( empty( $this->name ) || empty( $this->value ) )
    15411541                        return '';
    15421542
    1543                 return $this->name . '=' . urlencode( $this->value );
     1543                return $this->name . '=' . $this->encodeString( $this->value );
    15441544        }
     1545       
     1546        /**
     1547         * URL encode non-printable characters only
     1548         *
     1549         * @link http://stackoverflow.com/a/1969339
     1550         *
     1551         * @param string $str
     1552         * @return string
     1553         */
     1554        public function encodeString( $str ) {
     1555            $chars = preg_split( '//', $str, -1, PREG_SPLIT_NO_EMPTY );
     1556            return implode( '', array_map( array( $this, 'encodeChar' ), $chars ) );
     1557        }
    15451558
     1559        /**
     1560         * Encode only non-printable chars
     1561         * @param string $char
     1562         * @return string
     1563         */
     1564        public function encodeChar( $char ) {
     1565            if ( ctype_print( $char ) && !in_array( $char, array( '=', ';', ' ', '%', '+' ) ) )
     1566                return $char;
     1567            return urlencode( $char );
     1568        }
     1569
    15461570        /**
    15471571         * Retrieve cookie header for usage in the rest of the WordPress HTTP API.
    15481572         *