Skip to content

Commit

Permalink
ZK-5756: a MatchMedia request causes java.lang.IllegalArgumentException
Browse files Browse the repository at this point in the history
  • Loading branch information
jumperchen authored and DevChu committed Sep 20, 2024
1 parent f6e448a commit 1366e21
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 6 deletions.
12 changes: 7 additions & 5 deletions zkbind/src/main/java/org/zkoss/bind/impl/BinderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ private class VMsgsChangedListener implements EventListener<Event>, Serializable
private static final long serialVersionUID = 1L;

public void onEvent(Event event) throws Exception {
if (_validationMessages != null) {
if (_validationMessages != null && _rootComp.getDesktop() != null) {
Set<Property> notify = new HashSet<Property>();
notify.add(new PropertyImpl(_validationMessages, ".", null));
fireNotifyChanges(notify);
Expand Down Expand Up @@ -2680,10 +2680,12 @@ private class PostCommandListener implements EventListener<Event>, Serializable

@SuppressWarnings("unchecked")
public void onEvent(Event event) throws Exception {
Object[] data = (Object[]) event.getData();
String command = (String) data[0];
Map<String, Object> args = (Map<String, Object>) data[1];
sendCommand(command, args);
if (_rootComp.getDesktop() != null) {
Object[] data = (Object[]) event.getData();
String command = (String) data[0];
Map<String, Object> args = (Map<String, Object>) data[1];
sendCommand(command, args);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions zkdoc/release-note
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ ZK 10.1.0
ZK-5475: select a date with time produces an invalid result under locale pt
ZK-3729: getDesktop() sometimes returns NULL causing NPE
ZK-5707: avoid invoking an event listener after a session expired
ZK-5707: avoid invoking a event listener after a session expired
ZK-5756: a MatchMedia request causes java.lang.IllegalArgumentException

* Upgrade Notes
+ Remove Htmls.encodeJavaScript(), Strings.encodeJavaScript(), Strings.escape() with Strings.ESCAPE_JAVASCRIPT, and replace them with OWASP Java Encoder APIs instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* B101_ZK_5756_Page_A_VM.java
Purpose:
Description:
History:
5:59 PM 2024/9/19, Created by jumperchen
Copyright (C) 2024 Potix Corporation. All Rights Reserved.
*/
package org.zkoss.zktest.test2;

import org.zkoss.bind.annotation.MatchMedia;
import org.zkoss.lang.Threads;

/**
* @author jumperchen
*/
public class B101_ZK_5756_Page_A_VM {
@MatchMedia("all and (min-width: 958px)")
public void beWide(){
Threads.sleep(500);
}

@MatchMedia("all and (max-width: 957px)")
public void beNarrow(){
Threads.sleep(500);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* B101_ZK_5756_Page_B_VM.java
Purpose:
Description:
History:
6:00 PM 2024/9/19, Created by jumperchen
Copyright (C) 2024 Potix Corporation. All Rights Reserved.
*/
package org.zkoss.zktest.test2;

import org.zkoss.bind.annotation.MatchMedia;

/**
* @author jumperchen
*/
public class B101_ZK_5756_Page_B_VM {
@MatchMedia("all and (min-width: 958px)")
public void beWide(){

}

@MatchMedia("all and (max-width: 957px)")
public void beNarrow(){

}
}
20 changes: 20 additions & 0 deletions zktest/src/main/webapp/test2/B101-ZK-5756-a.zul
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
B101-ZK-5756-a.zul
Purpose:
Description:
History:
2024/9/19, Created by jumperchen
Copyright (C) 2024 Potix Corporation. All Rights Reserved.
-->
<zk>
<div viewModel="@id('vm') @init('org.zkoss.zktest.test2.B101_ZK_5756_Page_A_VM')">
page a
</div>
</zk>
20 changes: 20 additions & 0 deletions zktest/src/main/webapp/test2/B101-ZK-5756-b.zul
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
B101-ZK-5756-b.zul
Purpose:
Description:
History:
2024/9/19, Created by jumperchen
Copyright (C) 2024 Potix Corporation. All Rights Reserved.
-->
<zk>
<div viewModel="@id('vm')@init('org.zkoss.zktest.test2.B101_ZK_5756_Page_B_VM')">
page b
</div>
</zk>
50 changes: 50 additions & 0 deletions zktest/src/main/webapp/test2/B101-ZK-5756.zul
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
B101-ZK-5756.zul
Purpose:
Description:
History:
2024/9/19, Created by jumperchen
Copyright (C) 2024 Potix Corporation. All Rights Reserved.
-->
<zk xmlns:n="native" xmlns="http://www.zkoss.org/2005/zul">
<zscript><![CDATA[
public class NavigationModel {
private String contentUrl = "B101-ZK-5756-a.zul";
public String getContentUrl() {
return contentUrl;
}
public void setContentUrl(String contentUrl) {
this.contentUrl = contentUrl;
}
}
NavigationModel navigationModel = new NavigationModel();
public void toA(){
navigationModel.setContentUrl("B101-ZK-5756-a.zul");
BindUtils.postNotifyChange(navigationModel, "contentUrl");
}
public void toB(){
navigationModel.setContentUrl("B101-ZK-5756-b.zul");
BindUtils.postNotifyChange(navigationModel, "contentUrl");
}
]]></zscript>
<div apply="org.zkoss.bind.BindComposer">

<div sclass="sidebar">

<radiogroup>
<radio id="r1" label="page a" onCheck="toA()"/>
<radio id="r2" label="page b" onCheck="toB()"/>
</radiogroup>
</div>
<apply templateURI="@load(navigationModel.contentUrl)"/>
</div>
</zk>
3 changes: 2 additions & 1 deletion zktest/src/main/webapp/test2/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3138,7 +3138,8 @@ B90-ZK-4431.zul=A,E,Multislider
##zats##B101-ZK-5594.zul=A,E,Group,ListGroup,ROD,zkmax,Exception
##zats##B101-ZK-5475.zul=A,E,Datebox,PT,Locale,Format,Constraint
##zats##B101-ZK-3729.zul=A,E,Desktop,Session,Timeout,NPE,Multithreading
##Zats##B101-ZK-5707.zul=A,E,Session,Timeout,Event,Exception,Desktop
##zats##B101-ZK-5707.zul=A,E,Session,Timeout,Event,Exception,Desktop
##zats##B101-ZK-5756.zul=A,E,ServerMVVM,Exception,MatchMedia,Data-racing

##
# Features - 3.0.x version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* B101_ZK_5756Test.java
Purpose:
Description:
History:
3:07 PM 2024/9/20, Created by jumperchen
Copyright (C) 2024 Potix Corporation. All Rights Reserved.
*/
package org.zkoss.zktest.zats.test2;

import java.util.Random;

import org.junit.jupiter.api.Test;

import org.zkoss.test.webdriver.WebDriverTestCase;

/**
* @author jumperchen
*/
public class B101_ZK_5756Test extends WebDriverTestCase {
@Test
public void test() {
connect();
Random random = new Random();
for (int i = 0; i < 30; i++) {
check(jq("$r1"));
sleep(random.nextInt(100));
check(jq("$r2"));
assertNoZKError();
}
}
}

0 comments on commit 1366e21

Please sign in to comment.