[Httplib2-discuss] =?WINDOWS-1252?Q?Re:_[Httplib2-discuss]_Re:_Bug_#1455955:_Follo?= =?WINDOWS-1252?
Status: Beta
Brought to you by:
jcgregorio
From: Thomas B. <t.b...@gm...> - 2006-04-07 10:11:28
|
2006/4/3, Thomas Broyer <t.b...@gm...>: > There are two options here: > - unfold and normalize white space in _normalize_headers > - unfold and normalize white space only in _parse_www_authenticate, > only for www-authenticate or authentication-info headers before > processing [...] > And as I was investigating in _parse_www_authentication, I also > noticed quoted pairs (in quoted strings) are never "unquoted", so the > following (new) unit test fails: > res =3D httplib2._parse_www_authenticate({ 'www-authenticate': > 'Test realm=3D"a \\"test\\" realm"'}) > self.assertEqual(res['test']['realm'], 'a "test" realm') > as res['test']['realm'] contains 'a \\"test\\" realm'. > This (unquoting) can be done using either a regex and the "sub" > method, or splitting and joining the string. I personnaly have no > preference. > > Also (and finally), as strict WWW-Authenticate "parsing" might cause > unrecoverable errors (I mean, a parameter treated as an auth-scheme, > or consuming the following challenge, instead of exceptions), I tend > to go for the simpler regex ("strict send/lax receive") I provided in > my previous mail (it still needs some testing though). Or how about > putting both regexes in the code and providing a switch for the one to > use (e.g. "httplib2.USE_STRICT_WWW_AUTHENTICATE_PARSING =3D true", > defaulting to false)? The attached patch fixes bug #1461941 and: - unfold and normalize spaces in _normalize_headers (_parse_www_authenticate assumes unfolded header values; regex fixed to accept \t as well, just in case, so doesn't assume fully-normalized spaces, only unfolded header value) - unquote "quoted-pairs" (done with a regex, split/join version available in comments) - use relaxed parsing by default but can be switched to strict parsing using a global variable - adds unit tests exercising both regex's -- Thomas Broyer |