Skip to content

Commit

Permalink
[JXR-140] Proper URL handling
Browse files Browse the repository at this point in the history
  • Loading branch information
judby authored and rfscholte committed Sep 21, 2018
1 parent fb8790d commit ef8bb96
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
Expand Up @@ -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 -
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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>" ) );

}
}
29 changes: 29 additions & 0 deletions 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
{
}

0 comments on commit ef8bb96

Please sign in to comment.