You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2020/01/17 10:29:58 UTC

[wicket] branch master updated: WICKET-6724: replace empty inline JS in href by # and event.preventDefault

This is an automated email from the ASF dual-hosted git repository.

papegaaij pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new 95e5c4d  WICKET-6724: replace empty inline JS in href by # and event.preventDefault
95e5c4d is described below

commit 95e5c4d3e4e2e435e4710324a604259488e66d30
Author: Emond Papegaaij <em...@topicus.nl>
AuthorDate: Fri Jan 17 11:08:21 2020 +0100

    WICKET-6724: replace empty inline JS in href by # and event.preventDefault
---
 .../src/main/java/org/apache/wicket/ajax/markup/html/AjaxLink.java    | 3 ++-
 .../java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java  | 3 ++-
 .../wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html  | 4 ++--
 .../org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkTest.java     | 2 +-
 .../markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html    | 4 ++--
 .../wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html    | 4 ++--
 .../apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html  | 2 +-
 .../wicket/markup/html/border/HideableBorderPage_ExpectedResult.html  | 4 ++--
 .../wicket/markup/html/panel/InlinePanelPageExpectedResult_7.html     | 4 ++--
 .../wicket/markup/html/panel/InlinePanelPageExpectedResult_8.html     | 4 ++--
 10 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/AjaxLink.java b/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/AjaxLink.java
index 67c731e..f9d5bbf 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/AjaxLink.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/AjaxLink.java
@@ -88,6 +88,7 @@ public abstract class AjaxLink<T> extends AbstractLink implements IAjaxLink, IGe
 			@Override
 			protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
 			{
+				attributes.setPreventDefault(true);
 				super.updateAjaxAttributes(attributes);
 				AjaxLink.this.updateAjaxAttributes(attributes);
 			}
@@ -117,7 +118,7 @@ public abstract class AjaxLink<T> extends AbstractLink implements IAjaxLink, IGe
 				tagName.equalsIgnoreCase("area"))
 			{
 				// disable any href attr in markup
-				tag.put("href", "javascript:;");
+				tag.put("href", "#");
 			}
 			else if (tagName.equalsIgnoreCase("button"))
 			{
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java b/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java
index d666bae..4a037e8 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxSubmitLink.java
@@ -101,6 +101,7 @@ public abstract class AjaxSubmitLink extends AbstractSubmitLink
 			@Override
 			protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
 			{
+				attributes.setPreventDefault(true);
 				super.updateAjaxAttributes(attributes);
 				AjaxSubmitLink.this.updateAjaxAttributes(attributes);
 			}
@@ -162,7 +163,7 @@ public abstract class AjaxSubmitLink extends AbstractSubmitLink
 				|| tagName.equalsIgnoreCase("area"))
 			{
 				// disable any href attr in markup
-				tag.put("href", "javascript:;");
+				tag.put("href", "#");
 			}
 			else if (tagName.equalsIgnoreCase("button"))
 			{
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html
index ce36c3b..e3bf2fe 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkPageExpectedResult.html
@@ -14,13 +14,13 @@ Wicket.Ajax.baseUrl="wicket/bookmarkable/org.apache.wicket.ajax.markup.html.ajax
 <script type="text/javascript" >
 /*<![CDATA[*/
 Wicket.Event.add(window, "domready", function(event) { 
-Wicket.Ajax.ajax({"u":"./org.apache.wicket.ajax.markup.html.ajaxLink.AjaxLinkPage?0-1.0-ajaxLink","c":"ajaxLink1","e":"click"});;
+Wicket.Ajax.ajax({"u":"./org.apache.wicket.ajax.markup.html.ajaxLink.AjaxLinkPage?0-1.0-ajaxLink","c":"ajaxLink1","e":"click","pd":true});;
 Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 ;});
 /*]]>*/
 </script>
 </head><body>
   <span wicket:id="ajaxLabel" id="ajaxLabel2">UpdateMe</span>
-  <a href="javascript:;" wicket:id="ajaxLink" id="ajaxLink1">Update</a>
+  <a href="#" wicket:id="ajaxLink" id="ajaxLink1">Update</a>
 </body>
 </html>
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkTest.java
index 8802913..41adf67 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkTest.java
@@ -42,7 +42,7 @@ class AjaxLinkTest extends WicketTestCase
 		TagTester ajaxLink = tester.getTagByWicketId("ajaxLink");
 
 		// It was a link to google in the markup, but should be replaced to "#"
-		assertTrue(ajaxLink.getAttributeIs("href", "javascript:;"));
+		assertTrue(ajaxLink.getAttributeIs("href", "#"));
 	}
 
 	/**
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html
index 77e9996..365e6b6 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPageExpectedResult.html
@@ -14,7 +14,7 @@ Wicket.Ajax.baseUrl="wicket/bookmarkable/org.apache.wicket.ajax.markup.html.ajax
 <script type="text/javascript" >
 /*<![CDATA[*/
 Wicket.Event.add(window, "domready", function(event) { 
-Wicket.Ajax.ajax({"u":"./org.apache.wicket.ajax.markup.html.ajaxLink.AjaxLinkWithBorderPage?0-1.0-border-border_body-ajaxLink","c":"ajaxLink1","e":"click"});;
+Wicket.Ajax.ajax({"u":"./org.apache.wicket.ajax.markup.html.ajaxLink.AjaxLinkWithBorderPage?0-1.0-border-border_body-ajaxLink","c":"ajaxLink1","e":"click","pd":true});;
 Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 ;});
 /*]]>*/
@@ -24,7 +24,7 @@ Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
     Border
     <wicket:body>
     <span wicket:id="ajaxLabel" id="ajaxLabel2">UpdateMe</span>
-    <a href="javascript:;" wicket:id="ajaxLink" id="ajaxLink1">Update</a>
+    <a href="#" wicket:id="ajaxLink" id="ajaxLink1">Update</a>
   </wicket:body>
     Border
   </wicket:border></span>
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html
index 8163e78..43cbd65 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2_ExpectedResult.html
@@ -14,7 +14,7 @@ Wicket.Ajax.baseUrl="wicket/bookmarkable/org.apache.wicket.ajax.markup.html.ajax
 <script type="text/javascript" >
 /*<![CDATA[*/
 Wicket.Event.add(window, "domready", function(event) { 
-Wicket.Ajax.ajax({"u":"./org.apache.wicket.ajax.markup.html.ajaxLink.AjaxPage2?0-1.0-pageLayout-pageLayout_body-ajaxLink","c":"ajaxLink1","e":"click"});;
+Wicket.Ajax.ajax({"u":"./org.apache.wicket.ajax.markup.html.ajaxLink.AjaxPage2?0-1.0-pageLayout-pageLayout_body-ajaxLink","c":"ajaxLink1","e":"click","pd":true});;
 Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 ;});
 /*]]>*/
@@ -24,7 +24,7 @@ Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 			<span>Marker for border start</span>
 			<wicket:body>
 	  <span wicket:id="ajaxLabel" id="ajaxLabel2">AAAAAAA</span>
-	  <a href="javascript:;" wicket:id="ajaxLink" id="ajaxLink1">Update</a>
+	  <a href="#" wicket:id="ajaxLink" id="ajaxLink1">Update</a>
   </wicket:body>
 			<span>Marker for border end</span>
 		</wicket:border></span>
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html
index 28588f0..8c7ef18 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_13.html
@@ -18,7 +18,7 @@ Wicket.Ajax.baseUrl="wicket/bookmarkable/org.apache.wicket.markup.html.basic.Sim
 <script type="text/javascript" >
 /*<![CDATA[*/
 Wicket.Event.add(window, "domready", function(event) { 
-Wicket.Ajax.ajax({"u":"./org.apache.wicket.markup.html.basic.SimplePage_13?0-1.0-html","c":"html1","e":"click"});;
+Wicket.Ajax.ajax({"u":"./org.apache.wicket.markup.html.basic.SimplePage_13?0-1.0-html","c":"html1","e":"click","pd":true});;
 Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 ;});
 /*]]>*/
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/border/HideableBorderPage_ExpectedResult.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/border/HideableBorderPage_ExpectedResult.html
index 080bead..fc2407f 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/border/HideableBorderPage_ExpectedResult.html
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/border/HideableBorderPage_ExpectedResult.html
@@ -14,14 +14,14 @@ Wicket.Ajax.baseUrl="wicket/bookmarkable/org.apache.wicket.markup.html.border.Hi
 <script type="text/javascript" >
 /*<![CDATA[*/
 Wicket.Event.add(window, "domready", function(event) { 
-Wicket.Ajax.ajax({"u":"./org.apache.wicket.markup.html.border.HideableBorderPage?0-1.0-hideable-hideLink","c":"hideLink1","e":"click"});;
+Wicket.Ajax.ajax({"u":"./org.apache.wicket.markup.html.border.HideableBorderPage?0-1.0-hideable-hideLink","c":"hideLink1","e":"click","pd":true});;
 Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 ;});
 /*]]>*/
 </script>
 </head><body>
   <div wicket:id="hideable"><wicket:border>
-  <a wicket:id="hideLink" id="hideLink1" href="javascript:;">Hide contents</a>
+  <a wicket:id="hideLink" id="hideLink1" href="#">Hide contents</a>
   <div wicket:id="wrapper" id="wrapper2">
   <wicket:body>
     Contents <span wicket:id="content">label</span>
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPageExpectedResult_7.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPageExpectedResult_7.html
index 365ba0f..bf1b47a 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPageExpectedResult_7.html
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPageExpectedResult_7.html
@@ -14,7 +14,7 @@ Wicket.Ajax.baseUrl="wicket/bookmarkable/org.apache.wicket.markup.html.panel.Inl
 <script type="text/javascript" >
 /*<![CDATA[*/
 Wicket.Event.add(window, "domready", function(event) { 
-Wicket.Ajax.ajax({"u":"./org.apache.wicket.markup.html.panel.InlinePanelPage_7?0-1.0-provider-ajaxRefresh","c":"ajaxRefresh1","e":"click"});;
+Wicket.Ajax.ajax({"u":"./org.apache.wicket.markup.html.panel.InlinePanelPage_7?0-1.0-provider-ajaxRefresh","c":"ajaxRefresh1","e":"click","pd":true});;
 Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 ;});
 /*]]>*/
@@ -33,7 +33,7 @@ Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 
 
 
-<a wicket:id="ajaxRefresh" id="ajaxRefresh1" href="javascript:;">AJAX refresh</a>
+<a wicket:id="ajaxRefresh" id="ajaxRefresh1" href="#">AJAX refresh</a>
 
 </wicket:panel></div>
 
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPageExpectedResult_8.html b/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPageExpectedResult_8.html
index 34ad3cc9..77349f7 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPageExpectedResult_8.html
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/panel/InlinePanelPageExpectedResult_8.html
@@ -14,7 +14,7 @@ Wicket.Ajax.baseUrl="wicket/bookmarkable/org.apache.wicket.markup.html.panel.Inl
 <script type="text/javascript" >
 /*<![CDATA[*/
 Wicket.Event.add(window, "domready", function(event) { 
-Wicket.Ajax.ajax({"u":"./org.apache.wicket.markup.html.panel.InlinePanelPage_8?0-1.0-add","c":"add1","e":"click"});;
+Wicket.Ajax.ajax({"u":"./org.apache.wicket.markup.html.panel.InlinePanelPage_8?0-1.0-add","c":"add1","e":"click","pd":true});;
 Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 ;});
 /*]]>*/
@@ -25,7 +25,7 @@ Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
   <span wicket:id="number">0</span><br/>
   <div id="nextContainer2" style="display:none" data-wicket-placeholder=""></div>
 </div>
-<a wicket:id="add" id="add1" href="javascript:;">Add</a>
+<a wicket:id="add" id="add1" href="#">Add</a>