DaZuiZui opened a new pull request, #1100:
URL: https://github.com/apache/tomcat/pull/1100

   ## Problem
   
   `c639c7ef` (*Allow maxLocaleCount to soft fail*) changed `maxLocaleCount` so 
that extra `Accept-Language` locales are ignored instead of failing the 
request. The implementation in `Request.parseLocales()` does the opposite of 
keeping the locales inside the limit:
   
   ```java
   if (maxLocaleCount > -1 && this.locales.size() >= maxLocaleCount) {
       this.locales.removeLast();
       log.info(...);
   }
   addLocale(locale);
   ```
   
   Locales are added highest quality first. Once the list is full, 
`removeLast()` drops a locale that is still inside the limit, and the following 
`addLocale()` inserts the locale that should have been ignored.
   
   With `maxLocaleCount` 5 and `Accept-Language: en,fr,de,es,it,zh`:
   
   - expected: `en, fr, de, es, it`
   - actual: `en, fr, de, es, zh`
   
   The connector default is still 10. `getLocale()` still returns the first 
locale, so the wrong entry shows up in `getLocales()`. The existing tests only 
assert the count, so they still pass.
   
   `parseLocalesHeader()` still parses one entry past the limit so the overflow 
can be detected. That extra entry is what used to be swapped in.
   
   ## Fix
   
   Stop adding locales once `maxLocaleCount` is reached, and log the overflow 
once. The higher quality locales stay, and the remainder is ignored.
   
   Also aligned the comments and docs that still described the old "reject the 
request" behavior:
   
   - `Connector` field comment
   - `mbeans-descriptors.xml`
   - AJP `maxLocaleCount` docs (`http.xml` was already updated by `c639c7ef`)
   - the `coyoteRequest.tooManyLocales` message
   - `AcceptLanguage` parser comment
   
   `TestRequest` now checks which locales are kept, including 
`en;q=0.9,fr;q=0.8,de;q=0.1` with a limit of 2, which must return `en, fr`.
   
   ## Testing
   
   `ant` is not available in the environment used for this change, so the full 
`ant test` suite was not run. The touched sources were compiled with JDK 21 and 
the locale assertions above were executed against that build.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to