Skip to content

Commit de30dfb

Browse files
committed
Prefix domain name with // even when schema is missing (ocpsoft#86)
1 parent 5041ad6 commit de30dfb

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

‎addressbuilder/src/main/java/org/ocpsoft/urlbuilder/AddressResult.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ public String toString()
115115
StringBuilder result = new StringBuilder();
116116

117117
if (isSchemeSet())
118-
result.append(getScheme()).append("://");
118+
result.append(getScheme()).append(":");
119119

120120
if (isDomainSet())
121-
result.append(getDomain());
121+
result.append("//").append(getDomain());
122122

123123
if (isPortSet())
124124
result.append(":").append(getPort());

‎addressbuilder/src/test/java/org/ocpsoft/urlbuilder/AddressBuilderTest.java‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void testBuildPathWithParametersResult()
173173
@Test
174174
public void testBuildHostAndPath()
175175
{
176-
Assert.assertEquals("ocpsoft.org/store/23/buy",
176+
Assert.assertEquals("//ocpsoft.org/store/23/buy",
177177
AddressBuilder.begin()
178178
.domain("ocpsoft.org")
179179
.path("/store/{item}/{action}").set("item", 23).set("action", "buy").toString());
@@ -182,22 +182,22 @@ public void testBuildHostAndPath()
182182
@Test
183183
public void testBuildHostAndPathResult()
184184
{
185-
Assert.assertEquals("ocpsoft.org/store/23/buy",
185+
Assert.assertEquals("//ocpsoft.org/store/23/buy",
186186
AddressBuilder.begin().domain("ocpsoft.org")
187187
.path("/store/{item}/{action}").set("item", 23).set("action", "buy").build().toString());
188188
}
189189

190190
@Test
191191
public void testProtocolAndPort()
192192
{
193-
Assert.assertEquals("file://:80",
193+
Assert.assertEquals("file::80",
194194
AddressBuilder.begin().scheme("file").port(80).toString());
195195
}
196196

197197
@Test
198198
public void testProtocolAndPortResult()
199199
{
200-
Assert.assertEquals("file://:80",
200+
Assert.assertEquals("file::80",
201201
AddressBuilder.begin().scheme("file").port(80).build().toString());
202202
}
203203

@@ -237,4 +237,18 @@ public void testFromStringOnlyWithPathAndQuery()
237237
assertEquals("/search?q=foobar", address.getPathAndQuery());
238238
}
239239

240+
@Test
241+
public void testCreateSchemalessUrl()
242+
{
243+
244+
Address address = AddressBuilder.begin()
245+
.scheme(null)
246+
.domain("example.com")
247+
.path("/test.txt")
248+
.build();
249+
250+
assertEquals("//example.com/test.txt", address.toString());
251+
252+
}
253+
240254
}

‎config-servlet/src/test/java/org/ocpsoft/rewrite/servlet/config/CDNConfigurationTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.jboss.arquillian.container.test.api.Deployment;
2424
import org.jboss.arquillian.junit.Arquillian;
2525
import org.jboss.shrinkwrap.api.spec.WebArchive;
26-
import org.junit.Ignore;
2726
import org.junit.Test;
2827
import org.junit.runner.RunWith;
2928
import org.ocpsoft.rewrite.config.ConfigurationProvider;
@@ -59,7 +58,6 @@ public void testCDNRelocation() throws Exception
5958
}
6059

6160
@Test
62-
@Ignore // See: https://github.com/ocpsoft/rewrite/issues/86
6361
public void testCDNRelocationWithSchemalessURL() throws Exception
6462
{
6563

0 commit comments

Comments
 (0)