You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/05/26 12:09:46 UTC
[2/4] git commit: [OLINGO-284] Fixed content length calculation
[OLINGO-284] Fixed content length calculation
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/b9137177
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/b9137177
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/b9137177
Branch: refs/heads/olingo-266-tecsvc
Commit: b9137177589146a2da01480ef605055d84f9faa5
Parents: 5b5ff8e
Author: Michael Bolz <mi...@sap.com>
Authored: Mon May 26 10:26:00 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Mon May 26 10:26:00 2014 +0200
----------------------------------------------------------------------
.../core/edm/primitivetype/EdmBinary.java | 22 +++++++++++++++-----
.../core/edm/primitivetype/EdmBinaryTest.java | 2 ++
2 files changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b9137177/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java
index 7611045..ee85d17 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java
@@ -53,11 +53,23 @@ public class EdmBinary extends SingletonPrimitiveType {
}
private static boolean validateMaxLength(final String value, final Integer maxLength) {
- return maxLength == null ? true
- : // Every three bytes are represented as four base-64 characters.
- // Additionally, there could be up to two padding "=" characters
- // if the number of bytes is not a multiple of three.
- maxLength >= value.length() * 3 / 4 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0);
+ return maxLength == null ? true :
+ // Every three bytes are represented as four base-64 characters.
+ // Additionally, there could be up to two padding "=" characters
+ // if the number of bytes is not a multiple of three,
+ // and there could be line feeds, possibly with carriage returns.
+ maxLength >= (value.length() - lineEndingsLength(value)) * 3 / 4
+ - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0);
+ }
+
+ private static int lineEndingsLength(final String value) {
+ int result = 0;
+ int index = 0;
+ while ((index = value.indexOf('\n', index)) >= 0) {
+ result += index > 0 && value.charAt(index - 1) == '\r' ? 2 : 1;
+ index++;
+ }
+ return result;
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b9137177/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinaryTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinaryTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinaryTest.java
index d052674..95c93f8 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinaryTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinaryTest.java
@@ -97,6 +97,8 @@ public class EdmBinaryTest extends PrimitiveTypeBaseTest {
byte[].class)));
assertTrue(Arrays.equals(binary, instance.valueOfString("qrvM3e7_", null, Integer.MAX_VALUE, null, null, null,
byte[].class)));
+ assertTrue(Arrays.equals(binary, instance.valueOfString("\nqrvM\n3e7_\r\n", null, 6, null, null, null,
+ byte[].class)));
expectFacetsErrorInValueOfString(instance, "qrvM3e7_", null, 3, null, null, null);
expectContentErrorInValueOfString(instance, "@");