This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/struts.git
commit bc9b2eb5963cc6c38a5f5b1c99da5930d94b5cc8 Author: Lukasz Lenart <[email protected]> AuthorDate: Mon Nov 2 08:37:32 2026 +0100 WW-4164 chore(core): polish extension config validation and warnings Reject extension entries containing whitespace, word the non-default mapper warning as "may not be applied" (subclasses still reach the inbound path and outbound resolution applies regardless), document the protected actionExtensionResolver field and reorder the ActionExtensions import. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- .../org/apache/struts2/components/Component.java | 3 +++ .../providers/XmlDocConfigurationProvider.java | 6 ++--- .../org/apache/struts2/dispatcher/Dispatcher.java | 2 +- .../XmlConfigurationProviderExtensionTest.java | 9 +++++++ .../apache/struts2/dispatcher/DispatcherTest.java | 2 +- .../providers/struts-extension-whitespace.xml | 29 ++++++++++++++++++++++ 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/components/Component.java b/core/src/main/java/org/apache/struts2/components/Component.java index d1e9f7d2c..e4d9bc5fa 100644 --- a/core/src/main/java/org/apache/struts2/components/Component.java +++ b/core/src/main/java/org/apache/struts2/components/Component.java @@ -82,6 +82,9 @@ public class Component { protected ValueStack stack; protected Map<String, Object> attributes; protected ActionMapper actionMapper; + /** + * @since 7.5.0 + */ protected ActionExtensionResolver actionExtensionResolver; protected boolean throwExceptionOnELFailure; protected boolean performClearTagStateForTagPoolingServers = false; diff --git a/core/src/main/java/org/apache/struts2/config/providers/XmlDocConfigurationProvider.java b/core/src/main/java/org/apache/struts2/config/providers/XmlDocConfigurationProvider.java index 34cd92ab7..90f034f8e 100644 --- a/core/src/main/java/org/apache/struts2/config/providers/XmlDocConfigurationProvider.java +++ b/core/src/main/java/org/apache/struts2/config/providers/XmlDocConfigurationProvider.java @@ -26,7 +26,6 @@ import org.apache.struts2.config.ConfigurationException; import org.apache.struts2.config.ConfigurationProvider; import org.apache.struts2.config.ConfigurationUtil; import org.apache.struts2.config.entities.ActionConfig; -import org.apache.struts2.dispatcher.mapper.ActionExtensions; import org.apache.struts2.config.entities.ExceptionMappingConfig; import org.apache.struts2.config.entities.InterceptorConfig; import org.apache.struts2.config.entities.InterceptorMapping; @@ -36,6 +35,7 @@ import org.apache.struts2.config.entities.ResultConfig; import org.apache.struts2.config.entities.ResultTypeConfig; import org.apache.struts2.config.entities.UnknownHandlerConfig; import org.apache.struts2.config.impl.LocatableFactory; +import org.apache.struts2.dispatcher.mapper.ActionExtensions; import org.apache.struts2.inject.Container; import org.apache.struts2.inject.ContainerBuilder; import org.apache.struts2.inject.Inject; @@ -546,8 +546,8 @@ public abstract class XmlDocConfigurationProvider implements ConfigurationProvid } List<String> extensions = ActionExtensions.parse(element.getAttribute("extension")); for (String extension : extensions) { - if (extension.startsWith(".") || extension.contains("/")) { - throw new ConfigurationException(format("Invalid extension [%s] on [%s], it must not start with '.' or contain '/'", + if (extension.startsWith(".") || extension.contains("/") || StringUtils.containsWhitespace(extension)) { + throw new ConfigurationException(format("Invalid extension [%s] on [%s], it must not start with '.' or contain '/' or whitespace", extension, element.getAttribute("name")), location); } } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index 392bf252f..9ad214785 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -760,7 +760,7 @@ public class Dispatcher { .flatMap(actions -> actions.values().stream()) .anyMatch(config -> config.getExtensions() != null); if (declared) { - LOG.warn("Actions declare the extension attribute but the configured {} is not {}, the declared extensions will not be applied", + LOG.warn("Actions declare the extension attribute but the configured {} is not {}, the declared extensions may not be applied", ActionMapper.class.getSimpleName(), DefaultActionMapper.class.getSimpleName()); } } diff --git a/core/src/test/java/org/apache/struts2/config/providers/XmlConfigurationProviderExtensionTest.java b/core/src/test/java/org/apache/struts2/config/providers/XmlConfigurationProviderExtensionTest.java index 175c779a9..b07016fbd 100644 --- a/core/src/test/java/org/apache/struts2/config/providers/XmlConfigurationProviderExtensionTest.java +++ b/core/src/test/java/org/apache/struts2/config/providers/XmlConfigurationProviderExtensionTest.java @@ -35,6 +35,7 @@ public class XmlConfigurationProviderExtensionTest extends StrutsInternalTestCas private static final String CONFIG = "org/apache/struts2/config/providers/struts-extension.xml"; private static final String INVALID_CONFIG = "org/apache/struts2/config/providers/struts-extension-invalid.xml"; + private static final String WHITESPACE_CONFIG = "org/apache/struts2/config/providers/struts-extension-whitespace.xml"; public void testActionInheritsPackageChainExtension() { loadConfigurationProviders(new StrutsXmlConfigurationProvider(CONFIG)); @@ -84,6 +85,14 @@ public class XmlConfigurationProviderExtensionTest extends StrutsInternalTestCas .hasStackTraceContaining(".html"); } + public void testWhitespaceRejected() { + StrutsXmlConfigurationProvider provider = new StrutsXmlConfigurationProvider(WHITESPACE_CONFIG); + assertThatThrownBy(() -> loadConfigurationProviders(provider)) + .isInstanceOf(ConfigurationException.class) + .hasStackTraceContaining("[ json]") + .hasStackTraceContaining("[Spaced]"); + } + private ActionConfig actionConfig(String namespace, String name) { return configuration.getRuntimeConfiguration().getActionConfig(namespace, name); } diff --git a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java index a727586a4..35debebc6 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java @@ -643,7 +643,7 @@ public class DispatcherTest extends StrutsJUnit4InternalTestCase { initDispatcher(params); assertThat(capture.messages(Level.WARN)).singleElement().asString() - .contains("declared extensions will not be applied"); + .contains("declared extensions may not be applied"); } } diff --git a/core/src/test/resources/org/apache/struts2/config/providers/struts-extension-whitespace.xml b/core/src/test/resources/org/apache/struts2/config/providers/struts-extension-whitespace.xml new file mode 100644 index 000000000..0f664e697 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/config/providers/struts-extension-whitespace.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/* + * 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. + */ +--> +<!DOCTYPE struts PUBLIC + "-//Apache Software Foundation//DTD Struts Configuration 7.5//EN" + "https://struts.apache.org/dtds/struts-7.5.dtd"> +<struts> + <package name="extension-whitespace"> + <action name="Spaced" class="org.apache.struts2.TestAction" extension="html, json"/> + </package> +</struts>
