You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by so...@apache.org on 2022/06/08 16:08:47 UTC

[wicket] branch master updated: [WICKET-6988] String.format is replaced with concatenation of strings

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

solomax 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 a695e4be3e [WICKET-6988] String.format is replaced with concatenation of strings
a695e4be3e is described below

commit a695e4be3e65cd1b2847d4b227cf4ad83981ecae
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Wed Jun 8 17:53:06 2022 +0700

    [WICKET-6988] String.format is replaced with concatenation of strings
---
 .../wicket/ajax/AbstractAjaxTimerBehavior.java     |  3 +-
 .../apache/wicket/ajax/AjaxTimerBehaviorTest.java  | 59 +++++++++++++++++++---
 2 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java
index 0e6fafd56e..a4291a3f68 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractAjaxTimerBehavior.java
@@ -197,8 +197,7 @@ public abstract class AbstractAjaxTimerBehavior extends AbstractDefaultAjaxBehav
 		timerId = getTimerId();
 
 		headerResponse.render(
-			OnLoadHeaderItem.forScript(String.format("Wicket.Timer.set('%s', function(){%s}, %d);",
-				timerId, js, updateInterval.toMillis())));
+			OnLoadHeaderItem.forScript("Wicket.Timer.set('" + timerId + "', function(){" + js + "}, " + updateInterval.toMillis() + ");"));
 	}
 
 	private void clearTimeout(IHeaderResponse headerResponse)
diff --git a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java
index 9a6a3d6bb6..fbd7c26f83 100644
--- a/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/ajax/AjaxTimerBehaviorTest.java
@@ -28,6 +28,8 @@ import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.model.Model;
 import org.apache.wicket.util.tester.WicketTestCase;
 import java.time.Duration;
+import java.util.Locale;
+
 import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,7 +48,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
 	 * Tests timer behavior in a component added to an AjaxRequestTarget
 	 */
 	@Test
-    void addedInAjaxSetsTimout()
+	void addedInAjaxSetsTimout()
 	{
 		Duration dur = Duration.ofSeconds(20);
 		final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
@@ -83,12 +85,11 @@ class AjaxTimerBehaviorTest extends WicketTestCase
 		assertMatches("Wicket.Timer.set", 1);
 	}
 
-
 	/**
 	 * tests timer behavior in a WebPage.
 	 */
 	@Test
-    void pageRenderSetsTimeout()
+	void pageRenderSetsTimeout()
 	{
 		Duration dur = Duration.ofSeconds(20);
 		final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
@@ -125,7 +126,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
 	 * tests timer behavior in a WebPage.
 	 */
 	@Test
-    void ajaxUpdateDoesNotSetTimeout()
+	void ajaxUpdateDoesNotSetTimeout()
 	{
 		Duration dur = Duration.ofSeconds(20);
 		final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
@@ -162,7 +163,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
 	/**
 	 */
 	@Test
-    void setVisibleSetsTimeout()
+	void setVisibleSetsTimeout()
 	{
 		Duration dur = Duration.ofSeconds(20);
 		final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
@@ -201,10 +202,11 @@ class AjaxTimerBehaviorTest extends WicketTestCase
 	/**
 	 */
 	@Test
-    void setDisabledClearsTimeout()
+	void setDisabledClearsTimeout()
 	{
 		final AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.ofSeconds(20))
 		{
+			private static final long serialVersionUID = 1L;
 			private boolean enabled = true;
 			
 			@Override
@@ -251,7 +253,7 @@ class AjaxTimerBehaviorTest extends WicketTestCase
 	 * WICKET-1525, WICKET-2152
 	 */
 	@Test
-    void restartResultsInAddTimeout()
+	void restartResultsInAddTimeout()
 	{
 		final Integer labelInitialValue = Integer.valueOf(0);
 
@@ -332,6 +334,49 @@ class AjaxTimerBehaviorTest extends WicketTestCase
 		tester.assertLabel(labelPath, String.valueOf(labelInitialValue + 2));
 	}
 
+	/**
+	 * Tests timer behavior in a component added to an AjaxRequestTarget
+	 */
+	@Test
+	void arabicAddedInAjaxSetsTimout()
+	{
+		Locale def = Locale.getDefault();
+		try {
+			Locale.setDefault(Locale.forLanguageTag("ar-EG"));
+			Duration dur = Duration.ofSeconds(20);
+			final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
+			final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
+
+			page.add(new WebComponent(MockPageWithLinkAndComponent.COMPONENT_ID)
+				.setOutputMarkupId(true));
+
+
+			page.add(new AjaxLink<Void>(MockPageWithLinkAndComponent.LINK_ID)
+			{
+				private static final long serialVersionUID = 1L;
+
+				@Override
+				public void onClick(AjaxRequestTarget target)
+				{
+					WebMarkupContainer wmc = new WebMarkupContainer(
+						MockPageWithLinkAndComponent.COMPONENT_ID);
+					wmc.setOutputMarkupId(true);
+					wmc.add(timer);
+					page.replace(wmc);
+					target.add(wmc);
+				}
+			});
+
+			tester.startPage(page);
+			tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
+
+			// first render sets timeout in correct Locale
+			assertMatches(", 20000", 1);
+		} finally {
+			Locale.setDefault(def);
+		}
+	}
+
 	/**
 	 * Validates the response, then makes sure the timer injects itself again when called.
 	 *