From 8bd229b40e30710525a056a4c395caf2565fe353 Mon Sep 17 00:00:00 2001 From: ramya vasanth Date: Fri, 22 Jan 2021 12:44:01 +0530 Subject: [PATCH] [OLINGO-1499]Fix case-sensitive handling of Content-Type header in BatchLineReader --- .../core/deserializer/batch/BatchLineReader.java | 3 ++- .../deserializer/batch/BatchLineReaderTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java index a27e311d9..be1b0e612 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java @@ -24,6 +24,7 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.http.HttpHeader; @@ -95,7 +96,7 @@ public class BatchLineReader { private void updateCurrentCharset(final String currentLine) { if (currentLine != null) { - if (currentLine.startsWith(HttpHeader.CONTENT_TYPE)) { + if (currentLine.toLowerCase(Locale.ENGLISH).startsWith(HttpHeader.CONTENT_TYPE.toLowerCase(Locale.ENGLISH))) { int cutOff = currentLine.endsWith(CRLF) ? 2 : currentLine.endsWith(LFS) ? 1 : 0; final ContentType contentType = ContentType.parse( currentLine.substring(HttpHeader.CONTENT_TYPE.length() + 1, currentLine.length() - cutOff).trim()); diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReaderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReaderTest.java index 7c8c01cba..4ec44a6fb 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReaderTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReaderTest.java @@ -270,6 +270,21 @@ public class BatchLineReaderTest { reader.close(); } + @Test + public void specialCharactersInJsonWithLowercaseContentType() throws Exception { + final String text = "\n" + + "content-type: application/json\n" + + "\n" + + "{\"text\": \"ä€ß\"}\n"; + BatchLineReader reader = create(text); + reader.readLine(); + reader.readLine(); + reader.readLine(); + assertEquals("{\"text\": \"ä€ß\"}\n", reader.readLine()); + assertNull(reader.readLine()); + reader.close(); + } + @Test public void rawBytes() throws Exception { byte[] content = new byte[Byte.MAX_VALUE - Byte.MIN_VALUE + 1];