Skip to content

Commit 58c0c6d

Browse files
committed
[MJAVADOC-539] Strip index.html from redirect URLs
1 parent ff04883 commit 58c0c6d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pom.xml

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ under the License.
119119
<contributor>
120120
<name>Michael Stumpf</name>
121121
</contributor>
122+
<contributor>
123+
<name>Julian Reschke</name>
124+
</contributor>
122125
</contributors>
123126

124127
<dependencies>

src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java

+28-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.lang.reflect.Modifier;
3333
import java.net.SocketTimeoutException;
3434
import java.net.URI;
35+
import java.net.URISyntaxException;
3536
import java.net.URL;
3637
import java.net.URLClassLoader;
3738
import java.nio.charset.Charset;
@@ -1554,7 +1555,33 @@ protected static URL getRedirectUrl( URL url, Settings settings )
15541555
}
15551556

15561557
List<URI> redirects = httpContext.getRedirectLocations();
1557-
return isEmpty( redirects ) ? url : redirects.get( redirects.size() - 1 ).toURL();
1558+
1559+
if ( isEmpty( redirects ) )
1560+
{
1561+
return url;
1562+
}
1563+
else
1564+
{
1565+
URI last = redirects.get( redirects.size() - 1 );
1566+
1567+
// URI must refer to directory, so prevent redirects to index.html
1568+
// see https://issues.apache.org/jira/browse/MJAVADOC-539
1569+
String truncate = "index.html";
1570+
if ( last.getPath().endsWith( "/" + truncate ) )
1571+
{
1572+
try
1573+
{
1574+
String fixedPath = last.getPath().substring( 0, last.getPath().length() - truncate.length() );
1575+
last = new URI( last.getScheme(), last.getAuthority(), fixedPath, last.getQuery(),
1576+
last.getFragment() );
1577+
}
1578+
catch ( URISyntaxException ex )
1579+
{
1580+
// not supposed to happen, but when it does just keep the last URI
1581+
}
1582+
}
1583+
return last.toURL();
1584+
}
15581585
}
15591586
}
15601587

0 commit comments

Comments
 (0)