Repository: olingo-odata2 Updated Branches: refs/heads/master f86e307fe -> a95331e5a
[OLINGO-284] Fixed content length calculation Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/a95331e5 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/a95331e5 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/a95331e5 Branch: refs/heads/master Commit: a95331e5a89cfc012e383c6c4a575661df52a37b Parents: f86e307 Author: Michael Bolz <[email protected]> Authored: Wed May 14 08:01:26 2014 +0200 Committer: Michael Bolz <[email protected]> Committed: Wed May 14 08:01:26 2014 +0200 ---------------------------------------------------------------------- .../apache/olingo/odata2/core/edm/EdmBinary.java | 17 +++++++---------- .../olingo/odata2/core/edm/EdmSimpleTypeTest.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a95331e5/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmBinary.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmBinary.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmBinary.java index 9922cb0..2cf5020 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmBinary.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmBinary.java @@ -70,22 +70,19 @@ public class EdmBinary extends AbstractSimpleType { : // In default representation, 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 carriage return/line feed combinations. - facets.getMaxLength() >= value.length() * 3 / 4 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0) - - crlfLength(value); + // not a multiple of three, and there could be line feeds, possibly with carriage returns. + facets.getMaxLength() * 4L >= (value.length() - crlfLength(value)) * 3L + - (value.contains("==") ? 2 : value.contains("=") ? 1 : 0) * 4L; } private static int crlfLength(final String value) { int result = 0; int index = 0; - while (index >= 0) { - index = value.indexOf("\r\n", index); - if (index > 0) { - result++; - index++; - } + while ((index = value.indexOf('\n', index)) >= 0) { + result += index > 0 && value.charAt(index - 1) == '\r' ? 2 : 1; + index++; } - return result * 2; + return result; } @Override http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a95331e5/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java index 9a80bce..7ddb197 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java @@ -1042,6 +1042,10 @@ public class EdmSimpleTypeTest extends BaseTest { getMaxLengthFacets(2), byte[].class))); assertTrue(Arrays.equals(binary, instance.valueOfString("qrvM\r\n3e7/\r\n", EdmLiteralKind.DEFAULT, getMaxLengthFacets(6), byte[].class))); + assertTrue(Arrays.equals(binary, instance.valueOfString("\nqrvM3e7/", EdmLiteralKind.DEFAULT, + getMaxLengthFacets(6), byte[].class))); + assertTrue(Arrays.equals(binary, instance.valueOfString("qrvM\n3e7/", EdmLiteralKind.DEFAULT, + getMaxLengthFacets(6), byte[].class))); assertTrue(Arrays.equals(binary, instance.valueOfString("qrvM3e7/", EdmLiteralKind.DEFAULT, getMaxLengthFacets(Integer.MAX_VALUE), byte[].class))); assertTrue(Arrays.equals(binary, instance.valueOfString("X'AABBCCDDEEFF'", EdmLiteralKind.URI, @@ -1053,11 +1057,13 @@ public class EdmSimpleTypeTest extends BaseTest { assertTrue(Arrays.equals(binary, instance.valueOfString("X'AABBCCDDEEFF'", EdmLiteralKind.URI, getMaxLengthFacets(null), byte[].class))); - expectErrorInValueOfString(instance, "qrvM3e7/", EdmLiteralKind.DEFAULT, getMaxLengthFacets(3), + expectErrorInValueOfString(instance, "qrvM3e7/", EdmLiteralKind.DEFAULT, getMaxLengthFacets(5), + EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED); + expectErrorInValueOfString(instance, "qrvM3e7/", EdmLiteralKind.JSON, getMaxLengthFacets(5), EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED); - expectErrorInValueOfString(instance, "qrvM3e7/", EdmLiteralKind.JSON, getMaxLengthFacets(3), + expectErrorInValueOfString(instance, "binary'AABBCCDDEEFF'", EdmLiteralKind.URI, getMaxLengthFacets(5), EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED); - expectErrorInValueOfString(instance, "binary'AABBCCDDEEFF'", EdmLiteralKind.URI, getMaxLengthFacets(3), + expectErrorInValueOfString(instance, "qrvM3e7/\r", EdmLiteralKind.DEFAULT, getMaxLengthFacets(6), EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED); expectErrorInValueOfString(instance, "@", EdmLiteralKind.DEFAULT, null,
