Commit d0c8f801 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '1.5.x'

parents cdebfcde ad629055
...@@ -85,7 +85,16 @@ public class ResourceProperties implements ResourceLoaderAware { ...@@ -85,7 +85,16 @@ public class ResourceProperties implements ResourceLoaderAware {
} }
public void setStaticLocations(String[] staticLocations) { public void setStaticLocations(String[] staticLocations) {
this.staticLocations = staticLocations; this.staticLocations = appendSlashIfNecessary(staticLocations);
}
private String[] appendSlashIfNecessary(String[] staticLocations) {
String[] normalized = new String[staticLocations.length];
for (int i = 0; i < staticLocations.length; i++) {
String location = staticLocations[i];
normalized[i] = location.endsWith("/") ? location : location + "/";
}
return normalized;
} }
public Resource getWelcomePage() { public Resource getWelcomePage() {
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -18,7 +18,10 @@ package org.springframework.boot.autoconfigure.web; ...@@ -18,7 +18,10 @@ package org.springframework.boot.autoconfigure.web;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.testutil.Matched;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.endsWith;
/** /**
* Tests for {@link ResourceProperties}. * Tests for {@link ResourceProperties}.
...@@ -52,4 +55,17 @@ public class ResourcePropertiesTests { ...@@ -52,4 +55,17 @@ public class ResourcePropertiesTests {
assertThat(this.properties.getChain().getEnabled()).isFalse(); assertThat(this.properties.getChain().getEnabled()).isFalse();
} }
@Test
public void defaultStaticLocationsAllEndWithTrailingSlash() {
assertThat(this.properties.getStaticLocations()).are(Matched.by(endsWith("/")));
}
@Test
public void customStaticLocationsAreNormalizedToEndWithTrailingSlash() {
this.properties.setStaticLocations(new String[] { "/foo", "/bar", "/baz/" });
assertThat(this.properties.getStaticLocations()).containsExactly("/foo/", "/bar/",
"/baz/");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment