This is an automated email from the ASF dual-hosted git repository. dashorst pushed a commit to branch wicket-10.x in repository https://gitbox.apache.org/repos/asf/wicket.git
commit 4e13684ab441ac0490ef3c713c0733b94a74e77e Author: Pedro Santos <[email protected]> AuthorDate: Fri Oct 9 17:47:05 2026 -0300 Escape the css class the form writes into its hidden fields Form#writeHiddenFields builds the div that holds its hidden fields with String.format, and the css class it reads from the resource bundles went in as it stands. It now goes through Strings#escapeMarkup, as the css class the filter form writes into its hidden fields already does. A value the framework writes into markup is escaped by the code that writes it, whichever of them the value came from. Co-Authored-By: Claude Mythos 5.1 <[email protected]> --- .../markup/html/form/FormHiddenFieldsTest.java | 85 ++++++++++++++++++++++ .../org/apache/wicket/markup/html/form/Form.java | 2 +- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/FormHiddenFieldsTest.java b/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/FormHiddenFieldsTest.java new file mode 100644 index 0000000000..5cad3ca6fc --- /dev/null +++ b/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/FormHiddenFieldsTest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.markup.html.form; + +import java.util.Locale; + +import org.apache.wicket.Component; +import org.apache.wicket.MarkupContainer; +import org.apache.wicket.markup.IMarkupResourceStreamProvider; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.resource.loader.IStringResourceLoader; +import org.apache.wicket.util.resource.IResourceStream; +import org.apache.wicket.util.resource.StringResourceStream; +import org.apache.wicket.util.tester.WicketTestCase; +import org.junit.jupiter.api.Test; + +/** + * {@link Form#writeHiddenFields()} writes its markup as a string, so it has to escape what it puts + * into the attributes itself. + */ +class FormHiddenFieldsTest extends WicketTestCase +{ + /** + * The css class of the hidden div comes from the resource bundles. + */ + @Test + void cssClassIsEscaped() + { + tester.getApplication().getResourceSettings().getStringResourceLoaders().add(0, + new IStringResourceLoader() + { + @Override + public String loadStringResource(Class<?> clazz, String key, Locale locale, + String style, String variation) + { + return Form.HIDDEN_FIELDS_CSS_CLASS_KEY.equals(key) ? "a\"b" : null; + } + + @Override + public String loadStringResource(Component component, String key, Locale locale, + String style, String variation) + { + return loadStringResource((Class<?>)null, key, locale, style, variation); + } + }); + + tester.startPage(new TestPage()); + + tester.assertContains("class=\"a"b\""); + } + + /** a form */ + public static class TestPage extends WebPage implements IMarkupResourceStreamProvider + { + private static final long serialVersionUID = 1L; + + /** */ + public TestPage() + { + add(new Form<Void>("form")); + } + + @Override + public IResourceStream getMarkupResourceStream(MarkupContainer container, + Class<?> containerClass) + { + return new StringResourceStream( + "<html><body><form wicket:id=\"form\"></form></body></html>"); + } + } +} diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java index 06fe82c73a..1686520148 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java @@ -1847,7 +1847,7 @@ public class Form<T> extends WebMarkupContainer { getResponse().write(String.format("<div id=\"%s\" hidden=\"\" class=\"%s\">", getHiddenFieldsId(HIDDEN_FIELDS_PARAMS_IDX), - getString(HIDDEN_FIELDS_CSS_CLASS_KEY))); + Strings.escapeMarkup(getString(HIDDEN_FIELDS_CSS_CLASS_KEY)))); // if the parameters are not in the action attribute, they have to be written as hidden fields if (encodeUrlInHiddenFields()) {
