Skip to content

Commit

Permalink
Fix edge-case in gwt-rpc client deserialization
Browse files Browse the repository at this point in the history
Extracting the stream version (before actually parsing it)
failed when the version ends up being the only element in a
concatenated array.

Bug: #9536
Bug-Link: #9536
Change-Id: I4faa225e7ef6c990f588277aa287731aa07c22a0
  • Loading branch information
tbroyer committed Sep 22, 2017
1 parent 7e730fe commit 0654587
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ private native JavaScriptObject readJavaScriptObject() /*-{
private static int readVersion(String encodedString) {
String versionStr =
encodedString.substring(encodedString.lastIndexOf(",") + 1, encodedString.lastIndexOf("]"));
int pos = versionStr.lastIndexOf("[");
if (pos >= 0) {
versionStr = versionStr.substring(pos + 1);
}
return Integer.parseInt(versionStr.trim());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ public void testParsingVersion7() throws SerializationException {
assertTrue(Double.isNaN(reader.readDouble()));
}

/**
* Tests edge-case where version is moved to single item in concatenated array.
*
* See https://github.com/gwtproject/gwt/issues/9536
*/
public void testParsingVersion7ArrayConcats() throws SerializationException {
ClientSerializationStreamReader reader = new ClientSerializationStreamReader(null);

String encoded = "[42,[],0].concat([7])";

assertEquals(7, readVersion(encoded));

reader.prepareToRead(encoded);

assertEquals(7, reader.getVersion());

assertEquals(42, reader.readInt());
}

private native int readVersion(String encoded)/*-{
return @com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::readVersion(Ljava/lang/String;)(encoded);
}-*/;
Expand Down

0 comments on commit 0654587

Please sign in to comment.