Skip to content

Commit

Permalink
#18 problem reproduced
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Nov 15, 2016
1 parent c0ca45d commit e8e118b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/io/jare/tk/TkRelay.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
import java.util.regex.Pattern;
import org.takes.HttpException;
import org.takes.Request;
import org.takes.Response;
Expand All @@ -49,6 +50,14 @@
*/
final class TkRelay implements Take {

/**
* Validation pattern for destination URLs.
* @link https://tools.ietf.org/html/rfc3986
*/
private static final Pattern PTN = Pattern.compile(
"[A-Za-z0-9-._~:/\\?#@!\\$&'\\(\\)\\*\\+,;=`\\[]]+"
);

/**
* Base.
*/
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/io/jare/tk/TkRelayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.takes.HttpException;
import org.takes.Take;
import org.takes.facets.fork.FkRegex;
import org.takes.facets.fork.TkFork;
Expand Down Expand Up @@ -98,4 +99,21 @@ public void sendsRequestThroughToHome() throws Exception {
);
}

/**
* TkRelay can tolerate complex URLs.
* @throws Exception If some problem inside
*/
@Test(expected = HttpException.class)
public void catchesInvalidURLs() throws Exception {
new TkRelay(new FkBase()).act(
new RqFake(
Arrays.asList(
"GET /?u=http://www.yegor256.com/i+%D1%85%D0%BC",
"Host: 127.0.0.1"
),
""
)
);
}

}

0 comments on commit e8e118b

Please sign in to comment.