Changeset 42343 for trunk/src/wp-includes/class-wp-http-cookie.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-http-cookie.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-http-cookie.php
r41162 r42343 83 83 */ 84 84 public function __construct( $data, $requested_url = '' ) { 85 if ( $requested_url ) 85 if ( $requested_url ) { 86 86 $arrURL = @parse_url( $requested_url ); 87 if ( isset( $arrURL['host'] ) ) 87 } 88 if ( isset( $arrURL['host'] ) ) { 88 89 $this->domain = $arrURL['host']; 90 } 89 91 $this->path = isset( $arrURL['path'] ) ? $arrURL['path'] : '/'; 90 if ( '/' != substr( $this->path, -1 ) )92 if ( '/' != substr( $this->path, -1 ) ) { 91 93 $this->path = dirname( $this->path ) . '/'; 94 } 92 95 93 96 if ( is_string( $data ) ) { … … 96 99 97 100 // Special handling for first pair; name=value. Also be careful of "=" in value. 98 $name = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) );99 $value = substr( $pairs[0], strpos( $pairs[0], '=' ) + 1 );101 $name = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) ); 102 $value = substr( $pairs[0], strpos( $pairs[0], '=' ) + 1 ); 100 103 $this->name = $name; 101 104 $this->value = urldecode( $value ); … … 106 109 // Set everything else as a property. 107 110 foreach ( $pairs as $pair ) { 108 $pair = rtrim( $pair);111 $pair = rtrim( $pair ); 109 112 110 113 // Handle the cookie ending in ; which results in a empty final pair. 111 if ( empty( $pair) )114 if ( empty( $pair ) ) { 112 115 continue; 116 } 113 117 114 118 list( $key, $val ) = strpos( $pair, '=' ) ? explode( '=', $pair ) : array( $pair, '' ); 115 $key = strtolower( trim( $key ) );116 if ( 'expires' == $key ) 119 $key = strtolower( trim( $key ) ); 120 if ( 'expires' == $key ) { 117 121 $val = strtotime( $val ); 122 } 118 123 $this->$key = $val; 119 124 } 120 125 } else { 121 if ( ! isset( $data['name'] ) )126 if ( ! isset( $data['name'] ) ) { 122 127 return; 128 } 123 129 124 130 // Set properties based directly on parameters. 125 131 foreach ( array( 'name', 'value', 'path', 'domain', 'port' ) as $field ) { 126 if ( isset( $data[ $field ] ) ) 132 if ( isset( $data[ $field ] ) ) { 127 133 $this->$field = $data[ $field ]; 128 } 129 130 if ( isset( $data['expires'] ) ) 134 } 135 } 136 137 if ( isset( $data['expires'] ) ) { 131 138 $this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] ); 132 else139 } else { 133 140 $this->expires = null; 141 } 134 142 } 135 143 } … … 146 154 */ 147 155 public function test( $url ) { 148 if ( is_null( $this->name ) ) 149 return false; 156 if ( is_null( $this->name ) ) { 157 return false; 158 } 150 159 151 160 // Expires - if expired then nothing else matters. 152 if ( isset( $this->expires ) && time() > $this->expires ) 153 return false; 161 if ( isset( $this->expires ) && time() > $this->expires ) { 162 return false; 163 } 154 164 155 165 // Get details on the URL we're thinking about sending to. 156 $url = parse_url( $url );166 $url = parse_url( $url ); 157 167 $url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' == $url['scheme'] ? 443 : 80 ); 158 168 $url['path'] = isset( $url['path'] ) ? $url['path'] : '/'; 159 169 160 170 // Values to use for comparison against the URL. 161 $path = isset( $this->path ) ? $this->path: '/';162 $port = isset( $this->port ) ? $this->port: null;171 $path = isset( $this->path ) ? $this->path : '/'; 172 $port = isset( $this->port ) ? $this->port : null; 163 173 $domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] ); 164 if ( false === stripos( $domain, '.' ) ) 174 if ( false === stripos( $domain, '.' ) ) { 165 175 $domain .= '.local'; 176 } 166 177 167 178 // Host - very basic check that the request URL ends with the domain restriction (minus leading dot). 168 179 $domain = substr( $domain, 0, 1 ) == '.' ? substr( $domain, 1 ) : $domain; 169 if ( substr( $url['host'], -strlen( $domain ) ) != $domain ) 170 return false; 180 if ( substr( $url['host'], -strlen( $domain ) ) != $domain ) { 181 return false; 182 } 171 183 172 184 // Port - supports "port-lists" in the format: "80,8000,8080". 173 if ( !empty( $port ) && !in_array( $url['port'], explode( ',', $port) ) ) 174 return false; 185 if ( ! empty( $port ) && ! in_array( $url['port'], explode( ',', $port ) ) ) { 186 return false; 187 } 175 188 176 189 // Path - request path must start with path restriction. 177 if ( substr( $url['path'], 0, strlen( $path ) ) != $path ) 178 return false; 190 if ( substr( $url['path'], 0, strlen( $path ) ) != $path ) { 191 return false; 192 } 179 193 180 194 return true; … … 189 203 */ 190 204 public function getHeaderValue() { 191 if ( ! isset( $this->name ) || ! isset( $this->value ) ) 205 if ( ! isset( $this->name ) || ! isset( $this->value ) ) { 192 206 return ''; 207 } 193 208 194 209 /**
Note: See TracChangeset
for help on using the changeset viewer.