Skip to content

Commit

Permalink
[MJAVADOC-539] Strip index.html from redirect URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
rfscholte committed Apr 29, 2019
1 parent ff04883 commit 58c0c6d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pom.xml
Expand Up @@ -119,6 +119,9 @@ under the License.
<contributor>
<name>Michael Stumpf</name>
</contributor>
<contributor>
<name>Julian Reschke</name>
</contributor>
</contributors>

<dependencies>
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
Expand Up @@ -32,6 +32,7 @@
import java.lang.reflect.Modifier;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -1554,7 +1555,33 @@ protected static URL getRedirectUrl( URL url, Settings settings )
}

List<URI> redirects = httpContext.getRedirectLocations();
return isEmpty( redirects ) ? url : redirects.get( redirects.size() - 1 ).toURL();

if ( isEmpty( redirects ) )
{
return url;
}
else
{
URI last = redirects.get( redirects.size() - 1 );

// URI must refer to directory, so prevent redirects to index.html
// see https://issues.apache.org/jira/browse/MJAVADOC-539
String truncate = "index.html";
if ( last.getPath().endsWith( "/" + truncate ) )
{
try
{
String fixedPath = last.getPath().substring( 0, last.getPath().length() - truncate.length() );
last = new URI( last.getScheme(), last.getAuthority(), fixedPath, last.getQuery(),
last.getFragment() );
}
catch ( URISyntaxException ex )
{
// not supposed to happen, but when it does just keep the last URI
}
}
return last.toURL();
}
}
}

Expand Down

0 comments on commit 58c0c6d

Please sign in to comment.