myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch 2.3.x updated: MYFACES-4281
Date Tue, 19 Mar 2019 16:30:11 GMT
This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch 2.3.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/2.3.x by this push:
     new 9943907  MYFACES-4281
9943907 is described below

commit 9943907ca5c79bf0e1b5dd4ca8c4cc337d390d9e
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Tue Mar 19 17:29:58 2019 +0100

    MYFACES-4281
---
 .../view/facelets/compiler/SAXCompiler.java        |  13 +-
 .../facelets/compiler/SkipNamespaceUnitTest.java   | 137 +++++++++++++++++++++
 .../facelets/compiler/testSkipNamespaceUnit.xhtml  |  27 ++++
 3 files changed, 176 insertions(+), 1 deletion(-)

diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
index 10b9d01..1373747 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
@@ -27,6 +27,8 @@ import java.util.regex.Pattern;
 import java.security.AccessController;
 import java.security.PrivilegedExceptionAction;
 import java.security.PrivilegedActionException;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 import javax.el.ELException;
@@ -75,6 +77,12 @@ public final class SAXCompiler extends Compiler
     private final static Pattern XML_DECLARATION = Pattern
             .compile("^<\\?xml.+?version=['\"](.+?)['\"](.+?encoding=['\"]((.+?))['\"])?.*?\\?>");
 
+    /**
+     * see https://issues.apache.org/jira/browse/MYFACES-4281
+     */
+    private final static List<String> SKIPPED_NAMESPACES = Arrays.asList("http://www.w3.org/1998/Math/MathML",
+            "http://www.w3.org/2000/svg","http://www.w3.org/1999/xlink");
+    
     private static class CompilationHandler extends DefaultHandler implements LexicalHandler
     {
 
@@ -258,7 +266,10 @@ public final class SAXCompiler extends Compiler
 
         public void startPrefixMapping(String prefix, String uri) throws SAXException
         {
-            this.unit.pushNamespace(prefix, uri);
+            if (!SKIPPED_NAMESPACES.contains(uri))
+            {
+                this.unit.pushNamespace(prefix, uri);
+            }
         }
 
         public void processingInstruction(String target, String data) throws SAXException
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/SkipNamespaceUnitTest.java
b/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/SkipNamespaceUnitTest.java
new file mode 100644
index 0000000..6b2b9fd
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/SkipNamespaceUnitTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.
+ */
+package org.apache.myfaces.view.facelets.compiler;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.apache.myfaces.shared.renderkit.html.HtmlResponseWriterImpl;
+
+import org.apache.myfaces.view.facelets.FaceletMultipleRequestsTestCase;
+import org.junit.Assert;
+import org.junit.Test;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+public class SkipNamespaceUnitTest extends FaceletMultipleRequestsTestCase 
+{
+
+    private Boolean isWellFormed = Boolean.FALSE;
+
+    public SkipNamespaceUnitTest() 
+    {
+        super();
+    }
+
+    public void setUp() throws Exception 
+    {
+        super.setUp();
+        setupRequest();
+    }
+
+    @Test
+    public void test() 
+    {
+        try 
+        {
+            StringWriter writer = new StringWriter();
+            HtmlResponseWriterImpl htmlResponseWriter = new HtmlResponseWriterImpl(writer,
"application/xml", "UTF-8");
+            facesContext.setResponseWriter(htmlResponseWriter);
+            String testData = "/testSkipNamespaceUnit.xhtml";
+            UIViewRoot view = facesContext.getViewRoot();
+            view.setViewId(testData);
+            vdl.buildView(facesContext, view, testData);
+            facesContext.renderResponse();
+            List<UIComponent> children = view.getChildren();
+            for (UIComponent child : children) 
+            {
+                if (child.isRendered()) 
+                {
+                    child.encodeAll(facesContext);
+                }
+            }
+            parse(writer);
+            Assert.assertTrue(isWellFormed);
+        } catch (IOException e) 
+        {
+            e.printStackTrace();
+        } catch (Exception e) 
+        {
+            e.printStackTrace();
+        }
+    }
+
+    private void parse(StringWriter sw) 
+    {
+        try 
+        {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            factory.setValidating(false);
+            factory.setNamespaceAware(true);
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            builder.setErrorHandler(new SimpleErrorHandler());
+            builder.parse(new InputSource(new StringReader(sw.toString())));
+            isWellFormed = Boolean.TRUE;
+        }
+        catch (ParserConfigurationException e) 
+        {
+            e.printStackTrace();
+        } 
+        catch (SAXException e) 
+        {
+            e.printStackTrace();
+        } 
+        catch (IOException e) 
+        {
+            e.printStackTrace();
+        } 
+        catch (Exception e) 
+        {
+            e.printStackTrace();
+        }
+        return;
+    }
+
+    public class SimpleErrorHandler implements ErrorHandler 
+    {
+        public void warning(SAXParseException e) throws SAXException 
+        {
+            System.out.println(e.getMessage());
+        }
+
+        public void error(SAXParseException e) throws SAXException 
+        {
+            System.out.println(e.getMessage());
+        }
+
+        public void fatalError(SAXParseException e) throws SAXException 
+        {
+            System.out.println(e.getMessage());
+        }
+    }
+}
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/compiler/testSkipNamespaceUnit.xhtml
b/impl/src/test/resources/org/apache/myfaces/view/facelets/compiler/testSkipNamespaceUnit.xhtml
new file mode 100644
index 0000000..6435701
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/compiler/testSkipNamespaceUnit.xhtml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+xmlns:ui="http://java.sun.com/jsf/facelets"
+xmlns:h="http://java.sun.com/jsf/html">
+<h:body>
+<dl>
+<dt>
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+<msup><mi>N</mi><mn>2</mn></msup>
+</math>
+</dt>
+<dd></dd>
+<dt>
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+<mi>C</mi>
+</math>
+</dt>
+<dd></dd>
+<dt>
+<math xmlns="http://www.w3.org/1998/Math/MathML">
+<mi>d</mi>
+</math>
+</dt>
+<dd></dd>
+</dl>
+</h:body>
+</html>


Mime
View raw message