Skip to content

Commit

Permalink
ensure string decoration for passed domain in URL-related methods
Browse files Browse the repository at this point in the history
Issue #13

Signed-off-by: Jonas Höf <[email protected]>
  • Loading branch information
jonashoef committed Sep 16, 2021
1 parent d3576f0 commit 77f267d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/src/main/java/com/tngtech/valueprovider/ValueProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ private String mergeZeroGroups(String address) {
* @return the generated URL.
*/
public URL url() {
return url(fixedDecoratedString("domain"));
return url("domain");
}

/**
Expand All @@ -941,7 +941,7 @@ public URL url() {
* Example:
* <pre>
* ValueProvider vp = ValueProviderFactory.createRandomValueProvider();
* vp.url("foo"); // -> "http://foo.com"
* vp.url("foo"); // -> "http://fooeFg.com"
* </pre>
* </p>
*
Expand All @@ -966,7 +966,7 @@ public URL url(String domain) {
* @return the generated URL.
*/
public URL httpUrl() {
return httpUrl(fixedDecoratedString("domain"));
return httpUrl("domain");
}

/**
Expand All @@ -975,7 +975,7 @@ public URL httpUrl() {
* Example:
* <pre>
* ValueProvider vp = ValueProviderFactory.createRandomValueProvider();
* vp.httpUrl("mydomain"); // -> "http://www.mydomain.com"
* vp.httpUrl("mydomain"); // -> "http://www.mydomainStu.com"
* </pre>
* </p>
*
Expand All @@ -1000,7 +1000,7 @@ public URL httpUrl(String domain) {
* @return the generated URL.
*/
public URL httpsUrl() {
return httpsUrl(fixedDecoratedString("domain"));
return httpsUrl("domain");
}

/**
Expand All @@ -1009,7 +1009,7 @@ public URL httpsUrl() {
* Example:
* <pre>
* ValueProvider vp = ValueProviderFactory.createRandomValueProvider();
* vp.httpsUrl("somedomain"); // -> "https://somedomain.co.uk"
* vp.httpsUrl("somedomain"); // -> "https://somedomainUVw.co.uk"
* </pre>
* </p>
*
Expand All @@ -1021,13 +1021,14 @@ public URL httpsUrl(String domain) {
}

private URL createUrl(String scheme, String domain) {
String decoratedDomain = fixedDecoratedString(domain);
String optionalWWWPrefix = "";
if (!domain.startsWith("www")) {
optionalWWWPrefix = booleanValue() ? "www." : "";
}
String countrySuffix = oneOf("de", "com", "net", "co.uk");
try {
return new URL(format("%s://%s%s.%s", scheme, optionalWWWPrefix, domain, countrySuffix));
return new URL(format("%s://%s%s.%s", scheme, optionalWWWPrefix, decoratedDomain, countrySuffix));
} catch (MalformedURLException e) {
throw new IllegalArgumentException(format("Illegal domain %s", domain));
}
Expand Down

0 comments on commit 77f267d

Please sign in to comment.