Make WordPress Core

Ticket #19922: 19922.3.patch

File 19922.3.patch, 1.7 KB (added by kurtpayne, 13 years ago)

Combining cookie spec and apply_filters approach from dllh

  • wp-includes/class-http.php

    Property changes on: wp-includes
    ___________________________________________________________________
    Added: svn:ignore
       + .19922.patch.swp
    
    
     
    419419                                $cookies_header .= $cookie->getHeaderValue() . '; ';
    420420                        }
    421421                        $cookies_header = substr( $cookies_header, 0, -2 );
     422                        $cookies_header = apply_filters( 'http_headers_cookie', $cookies_header );
    422423                        $r['headers']['cookie'] = $cookies_header;
    423424                }
    424425        }
     
    15401541                if ( empty( $this->name ) || empty( $this->value ) )
    15411542                        return '';
    15421543
    1543                 return $this->name . '=' . urlencode( $this->value );
     1544                return $this->name . '=' . $this->encodeString( $this->value );
    15441545        }
     1546       
     1547        /**
     1548         * URL encode non-printable characters only
     1549         *
     1550         * @link http://stackoverflow.com/a/1969339
     1551         *
     1552         * @param string $str
     1553         * @return string
     1554         */
     1555        public function encodeString( $str ) {
     1556            $chars = preg_split( '//', $str, -1, PREG_SPLIT_NO_EMPTY );
     1557            return implode( '', array_map( array( $this, 'encodeChar' ), $chars ) );
     1558        }
    15451559
     1560        /**
     1561         * Encode only non-printable chars
     1562         * @param string $char
     1563         * @return string
     1564         */
     1565        public function encodeChar( $char ) {
     1566            if ( ctype_print( $char ) && !in_array( $char, array( ';', ' ', '%', '+' ) ) )
     1567                return $char;
     1568            return rawurlencode( $char );
     1569        }
     1570
    15461571        /**
    15471572         * Retrieve cookie header for usage in the rest of the WordPress HTTP API.
    15481573         *