gnodet commented on code in PR #11185:
URL: https://github.com/apache/maven/pull/11185#discussion_r2386318288


##########
src/mdo/reader-stax.vm:
##########
@@ -246,51 +246,76 @@ public class ${className} {
 #end
     } //-- ${root.name} read(InputStream, boolean)
 
-    /**
-     * Method read.
-     *
-     * @param parser a parser object.
-     * @param strict a strict object.
-     * @throws XMLStreamException XMLStreamException if
-     * any.
-     * @return ${root.name}
-     */
+/**
+* Method read.
+*
+* @param parser a parser object.
+* @param strict a strict object.
+* @throws XMLStreamException XMLStreamException if any.
+* @return ${root.name}
+*/
 #if ( $locationTracking )
-    public ${root.name} read(XMLStreamReader parser, boolean strict, 
InputSource inputSrc) throws XMLStreamException {
+public ${root.name} read(XMLStreamReader parser, boolean strict, InputSource 
inputSrc) throws XMLStreamException {
 #else
-    public ${root.name} read(XMLStreamReader parser, boolean strict) throws 
XMLStreamException {
+public ${root.name} read(XMLStreamReader parser, boolean strict) throws 
XMLStreamException {
 #end
 #if ( $needXmlContext )
-        Deque<Object> context = new ArrayDeque<>();
+Deque<Object> context = new ArrayDeque<>();
 #end
-        $rootUcapName $rootLcapName = null;
-        int eventType = parser.getEventType();
-        boolean parsed = false;
-        while (eventType != XMLStreamReader.END_DOCUMENT) {
-            if (eventType == XMLStreamReader.START_ELEMENT) {
-                if (strict && ! "${rootTag}".equals(parser.getLocalName())) {
-                    throw new XMLStreamException("Expected root element 
'${rootTag}' but found '" + parser.getName() + "'", parser.getLocation(), null);
-                } else if (parsed) {
-                    // fallback, already expected a XMLStreamException due to 
invalid XML
-                    throw new XMLStreamException("Duplicated tag: 
'${rootTag}'", parser.getLocation(), null);
-                }
+$rootUcapName $rootLcapName = null;
+    int eventType = parser.getEventType();
+    boolean parsed = false;
+    while (eventType != XMLStreamReader.END_DOCUMENT) {
+    if (eventType == XMLStreamReader.START_ELEMENT) {
+    if (strict && ! "${rootTag}".equals(parser.getLocalName())) {
+    throw new XMLStreamException("Expected root element '${rootTag}' but found 
'" + parser.getName() + "'", parser.getLocation(), null);
+    } else if (parsed) {
+    throw new XMLStreamException("Duplicated tag: '${rootTag}'", 
parser.getLocation(), null);
+    }
+
+    // Enforce root namespace per model (strict mode).
+    String rootNs = parser.getNamespaceURI();
+    boolean hasNs = rootNs != null && !rootNs.isEmpty();
+    if (strict && hasNs) {
+    if ("project".equals("${rootTag}")) {
+    // Accept any official POM namespace version (e.g., 4.0.0, 4.1.0)
+    if (!rootNs.startsWith("http://maven.apache.org/POM/";)) {

Review Comment:
   These hardcoded values are wrong.  We generate much more readers than just 
those two: settings, lifecycles, extensions, plugin, toolchains...
   In addition, accepting metadata namespace when reading a POM is just plain 
wrong. 
   The way to go would be to define a variable for the template in the POM that 
generates the writer and only accept that one.
   Another thing to keep in mind is that the plugin configuration in the POM 
can actually contain external namespaces and this is valid.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to