You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ra...@apache.org on 2020/12/09 05:47:10 UTC

[olingo-odata4] branch master updated: [OLINGO-1499]Support simple new lines in batch requests

This is an automated email from the ASF dual-hosted git repository.

ramyav pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git


The following commit(s) were added to refs/heads/master by this push:
     new 917ec01  [OLINGO-1499]Support simple new lines in batch requests
917ec01 is described below

commit 917ec01043987626cebd6809a91c9e0ff44c411a
Author: ramya vasanth <ra...@sap.com>
AuthorDate: Wed Dec 9 11:16:57 2020 +0530

    [OLINGO-1499]Support simple new lines in batch requests
---
 .../server/core/deserializer/batch/BatchLineReader.java   | 14 +++++++++-----
 .../core/deserializer/batch/BatchLineReaderTest.java      | 15 +++++++++++++++
 2 files changed, 24 insertions(+), 5 deletions(-)

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 99d2b8c..a27e311 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
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License. You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -37,6 +37,7 @@ public class BatchLineReader {
   public static final String BOUNDARY = "boundary";
   public static final String DOUBLE_DASH = "--";
   public static final String CRLF = "\r\n";
+  public static final String LFS = "\n";
   private Charset currentCharset = DEFAULT_CHARSET;
   private String currentBoundary = null;
   private ReadState readState = new ReadState();
@@ -95,8 +96,9 @@ public class BatchLineReader {
   private void updateCurrentCharset(final String currentLine) {
     if (currentLine != null) {
       if (currentLine.startsWith(HttpHeader.CONTENT_TYPE)) {
+        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() - 2).trim());
+            currentLine.substring(HttpHeader.CONTENT_TYPE.length() + 1, currentLine.length() - cutOff).trim());
         if (contentType != null) {
           final String charsetString = contentType.getParameter(ContentType.PARAMETER_CHARSET);
           currentCharset = charsetString == null ?
@@ -110,7 +112,7 @@ public class BatchLineReader {
             currentBoundary = DOUBLE_DASH + boundary;
           }
         }
-      } else if (CRLF.equals(currentLine)) {
+      } else if (CRLF.equals(currentLine) || LFS.equals(currentLine)) {
         readState.foundLinebreak();
       } else if (isBoundary(currentLine)) {
         readState.foundBoundary();
@@ -120,7 +122,9 @@ public class BatchLineReader {
 
   private boolean isBoundary(final String currentLine) {
     return (currentBoundary + CRLF).equals(currentLine)
-        || (currentBoundary + DOUBLE_DASH + CRLF).equals(currentLine);
+        || (currentBoundary + LFS).equals(currentLine)
+        || (currentBoundary + DOUBLE_DASH + CRLF).equals(currentLine)
+        || (currentBoundary + DOUBLE_DASH + LFS).equals(currentLine);
   }
 
   String readLine() throws IOException {
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 810c743..7c8c01c 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
@@ -256,6 +256,21 @@ public class BatchLineReaderTest {
   }
 
   @Test
+  public void specialCharactersInJsonWithNewline() 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];
     // binary content, not a valid UTF-8 representation of a string