From d3b5ba7a361866ea96fcc64d3f76be9b5be3b8e4 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 28 Jan 2019 16:42:25 +0100 Subject: [PATCH] Add test case for HttpRequest with relative URIs Test case for #19890 --- .../web/util/UriComponentsBuilderTests.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java b/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java index 303c6df39b8..f6acf0b9e6a 100644 --- a/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.util.Map; import org.junit.Test; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.mock.web.test.MockHttpServletRequest; @@ -518,6 +519,29 @@ public class UriComponentsBuilderTests { assertEquals("/foo/", after.getPath()); } + @Test // gh-19890 + public void fromHttpRequestWithEmptyScheme() { + HttpRequest request = new HttpRequest() { + @Override + public String getMethodValue() { + return "GET"; + } + + @Override + public URI getURI() { + return UriComponentsBuilder.fromUriString("/").build().toUri(); + } + + @Override + public HttpHeaders getHeaders() { + return new HttpHeaders(); + } + }; + UriComponents result = UriComponentsBuilder.fromHttpRequest(request).build(); + + assertEquals("/", result.toString()); + } + @Test public void path() { UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");