Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/org/apache/tomcat/util/buf/ByteChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public boolean equalsIgnoreCase(String s) {
}
int off = start;
for (int i = 0; i < len; i++) {
if (Ascii.toLower(b[off++]) != Ascii.toLower(s.charAt(i))) {
if (s.charAt(i) > 0xff || Ascii.toLower(b[off++]) != Ascii.toLower(s.charAt(i))) {
return false;
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/org/apache/tomcat/util/buf/TestByteChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ public void testFindBytes() throws UnsupportedEncodingException {
Assert.assertEquals(-1, ByteChunk.findBytes(bytes, 2, 5, new byte[] { 'w' }));
}

@Test
public void testEqualsIgnoreCase() {
byte[] bytes = "Hello".getBytes();
ByteChunk bc = new ByteChunk();
bc.setBytes(bytes, 0, bytes.length);
Assert.assertTrue(bc.equalsIgnoreCase("heLLo"));
Assert.assertFalse(bc.equalsIgnoreCase("\u8a48\u8a65\u8a6c\u8a6c\u8a6f"));
}

@Test
public void testSerialization() throws Exception {
Expand Down
11 changes: 11 additions & 0 deletions test/org/apache/tomcat/util/http/TestMimeHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.tomcat.util.http;

import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -32,6 +33,16 @@ public class TestMimeHeaders {
public static final String HEADER_NAME_B = "bbb";
public static final String HEADER_NAME_C = "ccc";

@Test
public void testSetValueBytesIgnoresCase01() throws UnsupportedEncodingException {
MimeHeaders mh = new MimeHeaders();

byte[] bytes = HEADER_NAME_UC_STRING.getBytes("utf-8");
mh.setValue(HEADER_NAME_UC_STRING).setBytes(bytes, 0, bytes.length);
Assert.assertTrue(mh.getValue(HEADER_NAME_UC_STRING).equalsIgnoreCase(HEADER_NAME_MIXED_STRING));
Assert.assertFalse(mh.getValue(HEADER_NAME_UC_STRING).equalsIgnoreCase("\u8a54\u8a45\u8a53\u8a54"));
}

@Test
public void testSetValueStringIgnoresCase01() {
MimeHeaders mh = new MimeHeaders();
Expand Down