[EMAIL PROTECTED] wrote:
Author: markt
Date: Wed Dec  6 18:51:40 2006
New Revision: 483329

URL: http://svn.apache.org/viewvc?view=rev&rev=483329
Log:
Ensure accept-language header conforms to RFC 2616 and ignore it if it doesn't

Modified:
    
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/Request.java
    tomcat/container/tc5.5.x/webapps/docs/changelog.xml

Modified: 
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/Request.java
URL: 
http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/Request.java?view=diff&rev=483329&r1=483328&r2=483329
==============================================================================
--- 
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/Request.java
 (original)
+++ 
tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/Request.java
 Wed Dec  6 18:51:40 2006
@@ -161,6 +161,12 @@
/**
+     * The pattern to match locale language and country components against
+     */
+    protected static String localeRegex = "[a-zA-Z]{1,8}";
+
+
+    /**
      * The default Locale if none are specified.
      */
     protected static Locale defaultLocale = Locale.getDefault();
@@ -2482,6 +2488,9 @@
             String variant = null;
             int dash = entry.indexOf('-');
             if (dash < 0) {
+                if (!entry.matches(localeRegex)) {
+                    continue;
+                }
                 language = entry;
                 country = "";
                 variant = "";
@@ -2495,6 +2504,12 @@
                     country = cTemp;
                 } else {
                     variant = "";
+                }
+                if (!language.matches(localeRegex)) {
+                    continue;
+                }
+                if (!country.matches(localeRegex)) {
+                    continue;

I think a "for" loop with a check for each char in the locale would be better. String.matches recompiles (and matches) a regexp every time, so I think it would be a good idea to avoid it (this whole method is quite bad already, of course).

Rémy

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to