Skip to content

Commit

Permalink
ZATS-70: fix JS line comments causing Parse Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
szediwy authored and Robert Wenzel committed May 2, 2019
1 parent a945d4a commit 6c8f72f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 7 deletions.
12 changes: 11 additions & 1 deletion zats-mimic/src/main/java/org/zkoss/zats/mimic/DesktopAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import org.zkoss.zats.mimic.operation.OperationAgent;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop;

/**
* The desktop agent, represents a server-side ZK desktop
*
Expand Down Expand Up @@ -62,7 +64,15 @@ public interface DesktopAgent extends QueryAgent {
* Gets the <code>Clients.log</code> results.
*
* @return Messages. An empty list if no message.
* @since 2.0.1
* @since 2.1.0
*/
List<String> getZkLog();

/**
* Get the attached {@link Desktop} instance.
*
* @return the attached {@link Desktop} instance.
* @since 2.1.0
*/
Desktop getDesktop();
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ public DesktopAgent connect(String zulPath) {
flush(desktopAgent.getId());

return desktopAgent;
} catch (Exception e) {
throw new ZatsException(e.getMessage(), e);
} catch (Throwable t) {
throw new ZatsException(t.getMessage(), t);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ public static Map<String, Object> parseAuResponseFromLayout(String raw) {
Elements scripts = doc.getElementsByTag("script");
for (Element script : scripts) {
// fetch arguments of zkmx()
String text = script.html().replaceAll("[\\n\\r]", "");
String text = script.html();
// ZATS-34: layout response might have other client-side scripts
// using JS parser to fetch argument of zkmx()
if (text.contains("zkmx(")) {
zkmxArgs = fetchJavascriptFuntionArguments("zkmx", text);
zkmxArgs = fetchJavascriptFunctionArguments("zkmx", text);
if(zkmxArgs != null) {
break; // find first
}
Expand Down Expand Up @@ -183,15 +183,15 @@ public static Map<String, Object> parseAuResponseFromLayout(String raw) {
return map;

} catch (Exception e) {
throw new ZatsException(e.getMessage(), e);
throw new ZatsException("Code could not be parsed:\n" + raw, e);
}
}


/**
* @return an json array text contained specified function's arguments, or null otherwise.
*/
public static String fetchJavascriptFuntionArguments(final String funcName, String code) {
public static String fetchJavascriptFunctionArguments(final String funcName, String code) {
if (funcName == null || code == null) {
return null;
}
Expand Down
41 changes: 41 additions & 0 deletions zats-mimic/src/test/java/org/zkoss/zats/testcase/ScriptTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.zkoss.zats.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.zkoss.zats.mimic.ComponentAgent;
import org.zkoss.zats.mimic.DesktopAgent;
import org.zkoss.zats.mimic.Zats;
import org.zkoss.zul.Listcell;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class ScriptTest {

@BeforeClass
public static void init() {
Zats.init(".");
}

@AfterClass
public static void end() {
Zats.end();
}

@After
public void after() {
Zats.cleanup();
}

@Test
public void testSyntaxError() {
DesktopAgent desktopAgent = Zats.newClient().connect("/~./basic/script.zul");
assertTrue(true);
}


}
23 changes: 23 additions & 0 deletions zats-mimic/src/test/resources/web/basic/script.zul
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<zk xmlns="http://www.zkoss.org/2005/zul">

<script type="text/javascript">
setTimeout('a()', 400);
setTimeout('b()', 400);

function getJSElement(zkId) {

// This is a comment

var jqId = '$' + zkId;
var zkEl = zk.Widget.$(jq(jqId));

return document.getElementById(zkEl.uuid);
}
</script>

<div height="100%">

</div>
</zk>


1 change: 1 addition & 0 deletions zats/release-note
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ZATS Mimic 2.1.0

* Bugs
ZATS-69: Clients.clearBusy causes a NPE
ZATS-70: JS Line comments parse errors

* Upgrade Notes
+ Jetty dependency upped to 9.4.18
Expand Down

0 comments on commit 6c8f72f

Please sign in to comment.