Question

Based on RFC-2616: I have a UI for Users to input header names and values. I need to validate the values. somehow i figured out to validate the header names from https://github.com/rack/rack/pull/399

Any help would be appreciated!

No correct solution

OTHER TIPS

Here is what i have come up but still any suggestions would be highly appreciated

/**
 * RFC 2616 header value http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p1-messaging-22.html#rfc.section.3.2.4.p.3
 * word = token / quoted-string
 * token = 1*tchar
 * tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
 * / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
 * / DIGIT / ALPHA
 * ; any VCHAR, except special
 * special        = "(" / ")" / "<" / ">" / "@" / ","
 * / ";" / ":" / "\" / DQUOTE / "/" / "["
 * / "]" / "?" / "=" / "{" / "}"
 */
private function isValidHeaderValue($value)
{
    $tchar = preg_replace('/[\"][@<>?={}\[\]()\"\,\;\:\/\\\\][\"]+/', '', $value);
    $remaining = preg_replace('/[a-zA-Z0-9\s\"!#$%&\'*+-.^_`|~]+/', '', $tchar);
    return ($remaining) ? false : true;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top