elharo commented on code in PR #2170:
URL: https://github.com/apache/maven/pull/2170#discussion_r2007753105
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java:
##########
@@ -48,8 +48,37 @@
@Singleton
public class DefaultModelXmlFactory implements ModelXmlFactory {
@Override
+ @Nonnull
public Model read(@Nonnull XmlReaderRequest request) throws
XmlReaderException {
nonNull(request, "request");
+ Model model = doRead(request);
+ if (isModelVersionGreaterThan400(model)
+ &&
!model.getNamespaceUri().startsWith("http://maven.apache.org/POM/")) {
Review Comment:
Will getNamespaceUri return an empty string (i,.e. not null) when there is
no namespace?
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java:
##########
@@ -48,8 +48,37 @@
@Singleton
public class DefaultModelXmlFactory implements ModelXmlFactory {
@Override
+ @Nonnull
public Model read(@Nonnull XmlReaderRequest request) throws
XmlReaderException {
nonNull(request, "request");
+ Model model = doRead(request);
+ if (isModelVersionGreaterThan400(model)
+ &&
!model.getNamespaceUri().startsWith("http://maven.apache.org/POM/")) {
+ throw new XmlReaderException(
+ "Invalid namespace '" + model.getNamespaceUri() + "' for
model version " + model.getModelVersion(),
+ null,
+ null);
+ }
+ return model;
+ }
+
+ private boolean isModelVersionGreaterThan400(Model model) {
+ String version = model.getModelVersion();
+ if (version == null) {
+ return false;
+ }
+ try {
Review Comment:
There's no need to do all this parsing. The namespace URI should be a fixed,
known string and that remains true in future versions. We should not change the
namespace URI in new versions.
--
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]