You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2018/09/21 12:15:14 UTC

[GitHub] rfscholte closed pull request #11: [JXR-140] Proper URL handling

rfscholte closed pull request #11: [JXR-140] Proper URL handling
URL: https://github.com/apache/maven-jxr/pull/11
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java b/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
index 3f2feae..b236082 100644
--- a/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
+++ b/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
@@ -149,7 +149,7 @@
     /**
      * Description of the Field
      */
-    private static final String[] VALID_URI_SCHEMES = { "http://", "mailto:" };
+    private static final String[] VALID_URI_SCHEMES = { "http://", "https://", "mailto:" };
 
     /**
      * Specify the only characters that are allowed in a URI besides alpha and numeric characters. Refer RFC2396 -
@@ -535,7 +535,7 @@ private final String uriFilter( String line )
 
                 if ( end != -1 )
                 {
-                    String uri = line.substring( start, end );
+                    String uri = ( end + 1 == line.length() ) ? line.substring( start ) : line.substring( start, end );
 
                     line =
                         StringUtils.replace( line, uri, "<a href=\"" + uri + "\" target=\"alexandria_uri\">" + uri
diff --git a/maven-jxr/src/test/java/org/apache/maven/jxr/JavaCodeTransformTest.java b/maven-jxr/src/test/java/org/apache/maven/jxr/JavaCodeTransformTest.java
index e076e6f..5c93306 100644
--- a/maven-jxr/src/test/java/org/apache/maven/jxr/JavaCodeTransformTest.java
+++ b/maven-jxr/src/test/java/org/apache/maven/jxr/JavaCodeTransformTest.java
@@ -21,6 +21,7 @@
 
 import static org.junit.Assert.assertTrue;
 
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -85,4 +86,30 @@ public void testTransformWithEmptyClassFile()
         assertTrue( Files.exists( Paths.get( "target/EmptyClass.html" ) ) );
     }
 
+    /**
+     * Test proper handling of link
+     */
+    @Test
+    public void testLinkHandling()
+        throws Exception
+    {
+        Path sourceFile = Paths.get( "src/test/resources/ClassWithLink.java" );
+        assertTrue( Files.exists( sourceFile ) );
+
+        codeTransform.transform( sourceFile, Paths.get( "target/ClassWithLink.html" )
+            , Locale.ENGLISH, "ISO-8859-1", "ISO-8859-1", Paths.get( "." ), "", "" );
+        assertTrue( Files.exists( Paths.get( "target/ClassWithLink.html" ) ) );
+
+        byte[] bytes = Files.readAllBytes( Paths.get( "target/ClassWithLink.html" ) );
+        String content = new String( bytes, StandardCharsets.ISO_8859_1 );
+        // The proper link in its full length
+        assertTrue( content.contains(
+            "<a href=\"http://www.apache.org/licenses/LICENSE-2.0\" " +
+            "target=\"alexandria_uri\">http://www.apache.org/licenses/LICENSE-2.0</a></em>" ) );
+        // ...and the same link with https protocol
+        assertTrue( content.contains(
+            "<a href=\"https://www.apache.org/licenses/LICENSE-2.0\" " +
+            "target=\"alexandria_uri\">https://www.apache.org/licenses/LICENSE-2.0</a></em>" ) );
+
+    }
 }
diff --git a/maven-jxr/src/test/resources/ClassWithLink.java b/maven-jxr/src/test/resources/ClassWithLink.java
new file mode 100644
index 0000000..8bf0b12
--- /dev/null
+++ b/maven-jxr/src/test/resources/ClassWithLink.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+/**
+ * This is a sample class used for testing
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * @author Jesper Udby
+ */
+public class ClassWithLink
+{
+}
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services