]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix potential invalid JSON output in MetadataWriter (#14591)
authorJohannes Dahlström <johannesd@vaadin.com>
Wed, 3 Sep 2014 13:46:40 +0000 (16:46 +0300)
committerSauli Tähkäpää <sauli@vaadin.com>
Fri, 12 Sep 2014 13:46:28 +0000 (16:46 +0300)
Change-Id: I90ec428ae11727b9762d53ebb8d94f8c850c425b

server/src/com/vaadin/server/communication/MetadataWriter.java
server/tests/src/com/vaadin/server/communication/MetadataWriterTest.java

index 17c893fe4076c0bc777284b4d61f9d45637f499f..9c46e646926bcd6af675aeac51d4f66af8cb2a37 100644 (file)
@@ -70,6 +70,7 @@ public class MetadataWriter implements Serializable {
             if (metaOpen) {
                 writer.write(", ");
             }
+            metaOpen = true;
             writer.write("\"async\":true");
         }
 
index dee37ddc7f615704aadf42f107591f3fed3c5b10..afae14007e18951b28e7383f1c27579001f8578c 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.server.communication;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.io.IOException;
 import java.io.StringWriter;
 
 import org.junit.Assert;
@@ -92,4 +93,17 @@ public class MetadataWriterTest {
                 "{\"timedRedirect\":{\"interval\":15,\"url\":\"\"}}", writer
                         .getBuffer().toString());
     }
+
+    @Test
+    public void writeAsyncWithSystemMessages() throws IOException {
+        WrappedSession wrappedSession = mock(WrappedSession.class);
+        when(session.getSession()).thenReturn(wrappedSession);
+
+        disableSessionExpirationMessages(messages);
+
+        new MetadataWriter().write(ui, writer, false, true, messages);
+        Assert.assertEquals(
+                "{\"async\":true,\"timedRedirect\":{\"interval\":15,\"url\":\"\"}}",
+                writer.getBuffer().toString());
+    }
 }