#15423 [Com]: HTTP::negotiateLanguage() severely bugged.

From: Date: Tue, 24 Dec 2002 11:13:48 +0000
Subject: #15423 [Com]: HTTP::negotiateLanguage() severely bugged.
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-11826@lists.php.net to get a copy of this message
ID: 15423 Comment by: chris_se@gmx.net Reported By: vigna@acm.org Status: Closed Bug Type: PEAR related Operating System: Linux Red Hat 7.2 PHP Version: 4.1.1 Assigned To: mj New Comment: This function still does not behave compliant to RFC2616. (http://sunsite.iisc.ernet.in/collection/rfc/rfc2616.html#103) It uses the following regular expression: ^([a-z_-]+);[[:space:]]*q=([0-9\.]+) First of all, the quality is optional, in the case it is not supplied, the quality of 1 should be assumed. Next, the underscore ist _not_ allowed. (if any browser sends it (which I don't believe), its the problem of that browser) Further, this function would accept the following languages: en--us en-thisisaverylonglanguagecode which are _not_ allowed by the RFC. A better (but not perfect) regular expression would be: ^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;[[:space:]]*q=([0-9\.]+)) Another question: why do you use eregi instead of preg_match? Also, the fallback to the TLD should indeed be optional, because in my eyes the TLD can tell nothing about the language the user speaks. (vigna@acm.org already supplied an example) Previous Comments: ------------------------------------------------------------------------ [2002-11-30 03:58:43] vigna@acm.org Nothing has changed: the bug is still there. ------------------------------------------------------------------------ [2002-02-17 13:53:08] vigna@acm.org The bug in the regexp is still there: '^([a-z]+);[[:space:]]*q=([0-9\.]+)' Unless I'm *really* missing something, this will not accept, say, en-US from the browser. Another problem is the last part of the function: guessing the language from the domain should at least be given as an option. I think, for instance, to german-speaking people in Italy, which are very proud of speaking German and would be irritated and frustrated by a site giving content in Italian just because of their .it extension. ------------------------------------------------------------------------ [2002-02-11 08:08:42] mj@php.net I fixed the outstanding issue in CVS. The documentation will be updated around tomorrow. ------------------------------------------------------------------------ [2002-02-07 06:22:33] vigna@acm.org Is it possible to get CVS access? It did that some time ago, but now I cannot find a pointer in the PEAR site. The problem with "_" is that Linux uses that for locales. But an HTTP language negotiation should IMHO return the HTTP language, not some system-specific counterpart. The user has just to do a strtr if necessary. Better fix it now than breaking other code later... ------------------------------------------------------------------------ [2002-02-07 06:18:42] mj@php.net The first two problems have been fixed in CVS. I also think, that we can easily change the problem with the language code, but I would like to hear the opinion of the package maintainers. - Martin ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/15423 -- Edit this bug report at http://bugs.php.net/?id=15423&edit=1

« previous php.pear.dev (#11826) next »