This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jxr.git
The following commit(s) were added to refs/heads/master by this push:
new ef8bb96 [JXR-140] Proper URL handling
ef8bb96 is described below
commit ef8bb961770801742ed63cfdd4df7c04662a7fa3
Author: Jesper Udby <[email protected]>
AuthorDate: Fri Sep 21 14:15:12 2018 +0200
[JXR-140] Proper URL handling
---
.../org/apache/maven/jxr/JavaCodeTransform.java | 4 +--
.../apache/maven/jxr/JavaCodeTransformTest.java | 27 ++++++++++++++++++++
maven-jxr/src/test/resources/ClassWithLink.java | 29 ++++++++++++++++++++++
3 files changed, 58 insertions(+), 2 deletions(-)
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 @@ public class JavaCodeTransform
/**
* 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 @@ public class JavaCodeTransform
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 @@ package org.apache.maven.jxr;
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 class JavaCodeTransformTest
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