Author: markt Date: Tue Dec 11 13:51:41 2018 New Revision: 1848675 URL: http://svn.apache.org/viewvc?rev=1848675&view=rev Log: Implement the requirements of section 8.2.2 2c of the Servlet specification and prevent a web application from deploying if it has fragments with duplicate names and is configured to use relative ordering of fragments.
Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java?rev=1848675&r1=1848674&r2=1848675&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java Tue Dec 11 13:51:41 2018 @@ -84,7 +84,17 @@ public class FragmentJarScannerCallback fragment.setName(fragment.getURL().toString()); } fragment.setJarName(extractJarFileName(jar.getJarFileURL())); - fragments.put(fragment.getName(), fragment); + if (fragments.containsKey(fragment.getName())) { + // Duplicate. Mark the fragment that has already been found with + // this name as having a duplicate so Tomcat can handle it + // correctly when the fragments are being ordered. + String duplicateName = fragment.getName(); + fragments.get(duplicateName).setDuplicated(true); + // Rename the current fragment so it doesn't clash + fragment.setName(fragment.getURL().toString()); + } else { + fragments.put(fragment.getName(), fragment); + } } } Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties?rev=1848675&r1=1848674&r2=1848675&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties [UTF-8] (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties [UTF-8] Tue Dec 11 13:51:41 2018 @@ -32,6 +32,7 @@ webRuleSet.relativeOrderingCount=<orderi webXml.duplicateEnvEntry=Duplicate env-entry name [{0}] webXml.duplicateFilter=Duplicate filter name [{0}] +webXml.duplicateFragment=More than one fragment with the name [{0}] was found. This is not legal with relative ordering. See section 8.2.2 2c of the Servlet specification for details. Consider using absolute ordering. webXml.duplicateMessageDestination=Duplicate message-destination name [{0}] webXml.duplicateMessageDestinationRef=Duplicate message-destination-ref name [{0}] webXml.duplicateResourceEnvRef=Duplicate resource-env-ref name [{0}] Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java?rev=1848675&r1=1848674&r2=1848675&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java Tue Dec 11 13:51:41 2018 @@ -79,6 +79,19 @@ public class WebXml extends XmlEncodingB this.overridable = overridable; } + /* + * Ideally, fragment names will be unique. If they are not, Tomcat needs + * to know as the action that the specification requires (see 8.2.2 1.e and + * 2.c) varies depending on the ordering method used. + */ + private boolean duplicated = false; + public boolean isDuplicated() { + return duplicated; + } + public void setDuplicated(boolean duplicated) { + this.duplicated = duplicated; + } + /** * web.xml only elements * Absolute Ordering @@ -2237,6 +2250,13 @@ public class WebXml extends XmlEncodingB } } } else { + // Stage 0. Check there were no fragments with duplicate names + for (WebXml fragment : fragments.values()) { + if (fragment.isDuplicated()) { + throw new IllegalArgumentException( + sm.getString("webXml.duplicateFragment", fragment.getName())); + } + } // Stage 1. Make all dependencies bi-directional - this makes the // next stage simpler. for (WebXml fragment : fragments.values()) { Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1848675&r1=1848674&r2=1848675&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Dec 11 13:51:41 2018 @@ -50,6 +50,12 @@ <fix> <bug>63002</bug>: Fix setting rewrite qsdiscard flag. (remm) </fix> + <fix> + Implement the requirements of section 8.2.2 2c of the Servlet + specification and prevent a web application from deploying if it has + fragments with duplicate names and is configured to use relative + ordering of fragments. (markt) + </fix> </changelog> </subsection> </section> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org