This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 7c913da5db338f5976f4ba0dd5dee4c661c1daa6 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Oct 16 17:45:25 2019 +0100 Add a case sensitive / insensitive option to the token list parser --- .../apache/tomcat/util/http/parser/TokenList.java | 35 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/java/org/apache/tomcat/util/http/parser/TokenList.java b/java/org/apache/tomcat/util/http/parser/TokenList.java index 9ba88b0..49e50a5 100644 --- a/java/org/apache/tomcat/util/http/parser/TokenList.java +++ b/java/org/apache/tomcat/util/http/parser/TokenList.java @@ -29,15 +29,34 @@ public class TokenList { /** - * Parses a header of the form 1#token. + * Parses a header of the form 1#token, forcing all parsed values to lower + * case. This is typically used when header values are case-insensitive. * * @param input The header to parse * @param result The Collection (usually a list of a set) to which the - * parsed token should be added + * parsed token should be added * * @throws IOException If an I/O error occurs reading the header */ public static void parseTokenList(Reader input, Collection<String> result) throws IOException { + parseTokenList(input, true, result); + } + + + /** + * Parses a header of the form 1#token. + * + * @param input The header to parse + * @param forceLowerCase Should parsed tokens be forced to lower case? This + * is intended for headers where the values are + * case-insensitive + * @param result The Collection (usually a list of a set) to which + * the parsed token should be added + * + * @throws IOException If an I/O error occurs reading the header + */ + public static void parseTokenList(Reader input, boolean forceLowerCase, Collection<String> result) + throws IOException { do { String fieldName = HttpParser.readToken(input); @@ -55,10 +74,18 @@ public class TokenList { SkipResult skipResult = HttpParser.skipConstant(input, ","); if (skipResult == SkipResult.EOF) { // EOF - result.add(fieldName.toLowerCase(Locale.ENGLISH)); + if (forceLowerCase) { + result.add(fieldName.toLowerCase(Locale.ENGLISH)); + } else { + result.add(fieldName); + } break; } else if (skipResult == SkipResult.FOUND) { - result.add(fieldName.toLowerCase(Locale.ENGLISH)); + if (forceLowerCase) { + result.add(fieldName.toLowerCase(Locale.ENGLISH)); + } else { + result.add(fieldName); + } continue; } else { // Not a token - ignore it --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org