You are here

public function SetCookie::validate in Lockr 7.3

Check if the cookie is valid according to RFC 6265

Return value

bool|string Returns true if valid or an error message if invalid

File

vendor/guzzlehttp/guzzle/src/Cookie/SetCookie.php, line 369

Class

SetCookie
Set-Cookie object

Namespace

GuzzleHttp\Cookie

Code

public function validate() {

  // Names must not be empty, but can be 0
  $name = $this
    ->getName();
  if (empty($name) && !is_numeric($name)) {
    return 'The cookie name must not be empty';
  }

  // Check if any of the invalid characters are present in the cookie name
  if (preg_match('/[\\x00-\\x20\\x22\\x28-\\x29\\x2c\\x2f\\x3a-\\x40\\x5c\\x7b\\x7d\\x7f]/', $name)) {
    return 'Cookie name must not contain invalid characters: ASCII ' . 'Control characters (0-31;127), space, tab and the ' . 'following characters: ()<>@,;:\\"/?={}';
  }

  // Value must not be empty, but can be 0
  $value = $this
    ->getValue();
  if (empty($value) && !is_numeric($value)) {
    return 'The cookie value must not be empty';
  }

  // Domains must not be empty, but can be 0
  // A "0" is not a valid internet domain, but may be used as server name
  // in a private network.
  $domain = $this
    ->getDomain();
  if (empty($domain) && !is_numeric($domain)) {
    return 'The cookie domain must not be empty';
  }
  return true;
}