Repository: ant-ivy
Updated Branches:
  refs/heads/master c4828bfd0 -> 4b6e0bd17


IVY-1562 Fix potential double encoding of "location" value of "extends" element 
in the ivy descriptor


Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/4b6e0bd1
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/4b6e0bd1
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/4b6e0bd1

Branch: refs/heads/master
Commit: 4b6e0bd179c5f728761c953249b6dda4d33fe18a
Parents: c4828bf
Author: Jaikiran Pai <jaiki...@apache.org>
Authored: Mon Jul 3 14:52:01 2017 +0530
Committer: Jaikiran Pai <jaiki...@apache.org>
Committed: Mon Jul 3 14:53:03 2017 +0530

----------------------------------------------------------------------
 .../parser/xml/XmlModuleDescriptorParser.java   |  9 ++--
 .../xml/XmlModuleDescriptorParserTest.java      | 55 ++++++++++++++++----
 .../xml/foo%2Fbar/hello/test-ivy-extends.xml    | 25 +++++++++
 .../plugins/parser/xml/foo%2Fbar/parent-ivy.xml | 27 ++++++++++
 4 files changed, 100 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/4b6e0bd1/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java 
b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
index cc640a8..63ed1f3 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
@@ -670,12 +670,11 @@ public class XmlModuleDescriptorParser extends 
AbstractModuleDescriptorParser {
 
             File file = new File(location);
             if (!file.isAbsolute()) {
-                URL url = 
settings.getRelativeUrlResolver().getURL(descriptorURL, location);
-                try {
-                    file = new File(new URI(url.toExternalForm()));
-                } catch (URISyntaxException e) {
-                    file = new File(url.getPath());
+                final URL url = 
settings.getRelativeUrlResolver().getURL(descriptorURL, location);
+                if (!url.getProtocol().equals("file")) {
+                    throw new IOException("Resolved location " + url + ", of 
parent module descriptor, is not a file");
                 }
+                file = new File(url.getPath());
             }
 
             file = FileUtil.normalize(file.getAbsolutePath());

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/4b6e0bd1/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java
----------------------------------------------------------------------
diff --git 
a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java
 
b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java
index 390d713..e2a62dd 100644
--- 
a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java
+++ 
b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java
@@ -17,15 +17,6 @@
  */
 package org.apache.ivy.plugins.parser.xml;
 
-import java.io.File;
-import java.io.IOException;
-import java.text.ParseException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashSet;
-
 import org.apache.ivy.Ivy;
 import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.core.module.descriptor.Configuration;
@@ -51,13 +42,26 @@ import org.apache.ivy.util.DefaultMessageLogger;
 import org.apache.ivy.util.FileUtil;
 import org.apache.ivy.util.Message;
 import org.apache.ivy.util.XMLHelper;
-
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-import static org.junit.Assert.*;
+import java.io.File;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 public class XmlModuleDescriptorParserTest extends 
AbstractModuleDescriptorParserTester {
     private IvySettings settings = null;
@@ -1447,4 +1451,33 @@ public class XmlModuleDescriptorParserTest extends 
AbstractModuleDescriptorParse
         assertEquals("mymodule", artifacts[0].getName());
         assertEquals("jar", artifacts[0].getType());
     }
+
+    /**
+     * Tests that when the <code>location</code> attribute of the 
<code>extends</code> element of a module descriptor
+     * file, includes any characters that {@link java.net.URI} considers as 
encoded characters (for example <code>%2F</code>)
+     * then the module descriptor and the location of the parent descriptor, 
are resolved and parsed correctly.
+     *
+     * @throws Exception
+     * @see <a 
href="https://issues.apache.org/jira/browse/IVY-1562";>IVY-1562</a> for more 
details
+     */
+    @Test
+    public void testExtendsEncodedLocation() throws Exception {
+        final ModuleDescriptor md = 
XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, 
getClass().getResource("foo%2Fbar/hello/test-ivy-extends.xml"), true);
+        assertNotNull("Parsed module descriptor is null", md);
+        assertEquals("Unexpected org for the parsed module descriptor", 
"myorg", md.getModuleRevisionId().getOrganisation());
+        assertEquals("Unexpected module name for the parsed module 
descriptor", "mymodule", md.getModuleRevisionId().getName());
+        assertEquals("Unexpected revision for the parsed module descriptor", 
"1.0.0", md.getModuleRevisionId().getRevision());
+
+        final Configuration[] confs = md.getConfigurations();
+        assertNotNull("No configurations found in module descriptor", confs);
+        assertEquals("Unexpected number of configurations found in module 
descriptor", 3, confs.length);
+
+        final Set<String> expectedConfs = new 
HashSet<>(Arrays.asList("parent-conf1", "parent-conf2", "conf2"));
+        for (final Configuration conf : confs) {
+            assertNotNull("One of the configurations was null in module 
descriptor", conf);
+            assertTrue("Unexpected configuration " + conf.getName() + " found 
in parsed module descriptor", expectedConfs.remove(conf.getName()));
+        }
+        assertTrue("Missing configurations " + expectedConfs + " from the 
parsed module descriptor", expectedConfs.isEmpty());
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/4b6e0bd1/test/java/org/apache/ivy/plugins/parser/xml/foo%2Fbar/hello/test-ivy-extends.xml
----------------------------------------------------------------------
diff --git 
a/test/java/org/apache/ivy/plugins/parser/xml/foo%2Fbar/hello/test-ivy-extends.xml
 
b/test/java/org/apache/ivy/plugins/parser/xml/foo%2Fbar/hello/test-ivy-extends.xml
new file mode 100644
index 0000000..fca2360
--- /dev/null
+++ 
b/test/java/org/apache/ivy/plugins/parser/xml/foo%2Fbar/hello/test-ivy-extends.xml
@@ -0,0 +1,25 @@
+<!--
+  ~ 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.
+  -->
+<ivy-module version="1.0">
+    <info organisation="myorg"
+          module="mymodule">
+        <extends organisation="myorg" module="myparent" revision="1.0.0" 
location="../../foo%2Fbar/parent-ivy.xml"/>
+    </info>
+    <configurations>
+        <conf name="conf2" visibility="private"/>
+    </configurations>
+</ivy-module>

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/4b6e0bd1/test/java/org/apache/ivy/plugins/parser/xml/foo%2Fbar/parent-ivy.xml
----------------------------------------------------------------------
diff --git 
a/test/java/org/apache/ivy/plugins/parser/xml/foo%2Fbar/parent-ivy.xml 
b/test/java/org/apache/ivy/plugins/parser/xml/foo%2Fbar/parent-ivy.xml
new file mode 100644
index 0000000..b54dc92
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/parser/xml/foo%2Fbar/parent-ivy.xml
@@ -0,0 +1,27 @@
+<!--
+  ~ 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.
+  -->
+<ivy-module version="1.0">
+    <info organisation="myorg"
+          module="myparent"
+          revision="1.0.0">
+        <description>Parent module description.</description>
+    </info>
+    <configurations>
+        <conf name="parent-conf1"/>
+        <conf name="parent-conf2" visibility="public"/>
+    </configurations>
+</ivy-module>

Reply via email to