Skip to content

Commit d3b5ba7

Browse files
committed
Add test case for HttpRequest with relative URIs
Test case for #19890
1 parent b8f7c37 commit d3b5ba7

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525

2626
import org.junit.Test;
2727

28+
import org.springframework.http.HttpHeaders;
2829
import org.springframework.http.HttpRequest;
2930
import org.springframework.http.server.ServletServerHttpRequest;
3031
import org.springframework.mock.web.test.MockHttpServletRequest;
@@ -518,6 +519,29 @@ public void fromHttpRequestWithTrailingSlash() {
518519
assertEquals("/foo/", after.getPath());
519520
}
520521

522+
@Test // gh-19890
523+
public void fromHttpRequestWithEmptyScheme() {
524+
HttpRequest request = new HttpRequest() {
525+
@Override
526+
public String getMethodValue() {
527+
return "GET";
528+
}
529+
530+
@Override
531+
public URI getURI() {
532+
return UriComponentsBuilder.fromUriString("/").build().toUri();
533+
}
534+
535+
@Override
536+
public HttpHeaders getHeaders() {
537+
return new HttpHeaders();
538+
}
539+
};
540+
UriComponents result = UriComponentsBuilder.fromHttpRequest(request).build();
541+
542+
assertEquals("/", result.toString());
543+
}
544+
521545
@Test
522546
public void path() {
523547
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");

0 commit comments

Comments
 (0)