veN1337 opened a new issue, #467:
URL: https://github.com/apache/maven-help-plugin/issues/467

   ### Affected version
   
   3.6.0
   
   ### Bug description
   
   If the POM contains an element with a namespace prefix and an xmlns: 
declaration, `help:effective-pom` writes the header comments first and `<?xml 
version="1.0"?>` after them. The XML is not pretty-printed and not well-formed 
(XML 1.0: the XML declaration must come first). Same symptom as #421.
   
   **Steps to reproduce:**
   ```xml
   <project xmlns="http://maven.apache.org/POM/4.0.0";>
     <modelVersion>4.0.0</modelVersion>
     <groupId>example</groupId>
     <artifactId>mre</artifactId>
     <version>1.0-SNAPSHOT</version>
     <packaging>pom</packaging>
     <build>
       <plugins>
         <plugin>
           <artifactId>maven-antrun-plugin</artifactId>
           <version>3.1.0</version>
           <configuration>
             <target>
               <ac:if xmlns:ac="antlib:net.sf.antcontrib">
                 <equals arg1="a" arg2="a"/>
                 <ac:then><echo message="hello"/></ac:then>
               </ac:if>
             </target>
           </configuration>
         </plugin>
       </plugins>
     </build>
   </project>
   ```
   
   `mvn org.apache.maven.plugins:maven-help-plugin:3.6.0:effective-pom 
-Doutput=ep.xml`
   
   **Expected:** ep.xml starts with `<?xml version="1.0" encoding="UTF-8"?>`, 
as with 3.5.2.
   **Actual:** ep.xml starts with `<!-- ===…; <?xml version="1.0"?>` appears 
after the comments.
   
   **Cause:**
   Introduced by the fix for #421 (#437). The regex in 
`AbstractEffectiveMojo.escapeNamespaceUnsafeElements()` only matches tags 
without attributes. `</ac:if>` is rewritten, but `<ac:if xmlns:ac="…">` is not, 
so the tags no longer match and JDOM fails:
   > org.jdom2.input.JDOMParseException: The element type "ac:if" must be 
terminated by the matching end-tag "</ac:if>".
   
   `prettyFormat()` swallows the exception and returns the raw output, 
including MavenXpp3Writer's own XML declaration. Nothing is logged.


-- 
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