diff --git a/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StandaloneAhcWSRequest.scala b/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StandaloneAhcWSRequest.scala index 3f451e08..d0ddeba8 100644 --- a/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StandaloneAhcWSRequest.scala +++ b/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StandaloneAhcWSRequest.scala @@ -5,7 +5,7 @@ package play.api.libs.ws.ahc import java.io.UnsupportedEncodingException -import java.net.URI +import java.net.{ URI, URISyntaxException } import java.nio.charset.{ Charset, StandardCharsets } import akka.stream.Materializer @@ -51,6 +51,7 @@ case class StandaloneAhcWSRequest( override def contentType: Option[String] = this.headers.get(HttpHeaders.Names.CONTENT_TYPE).map(_.head) + @throws[URISyntaxException]("If the url is invalid.") override lazy val uri: URI = { val enc = (p: String) => java.net.URLEncoder.encode(p, "utf-8") new java.net.URI(if (queryString.isEmpty) url else { diff --git a/play-ahc-ws-standalone/src/test/scala/play/api/libs/ws/ahc/AhcWSRequestSpec.scala b/play-ahc-ws-standalone/src/test/scala/play/api/libs/ws/ahc/AhcWSRequestSpec.scala index 5d838d51..9af3b762 100644 --- a/play-ahc-ws-standalone/src/test/scala/play/api/libs/ws/ahc/AhcWSRequestSpec.scala +++ b/play-ahc-ws-standalone/src/test/scala/play/api/libs/ws/ahc/AhcWSRequestSpec.scala @@ -4,6 +4,8 @@ package play.api.libs.ws.ahc +import java.net.URISyntaxException + import akka.actor.ActorSystem import akka.stream.ActorMaterializer import akka.util.ByteString @@ -16,6 +18,7 @@ import play.api.libs.ws._ import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaderNames import play.shaded.ahc.org.asynchttpclient.Realm.AuthScheme import play.shaded.ahc.org.asynchttpclient.{ Param, SignatureCalculator, Request => AHCRequest } + import scala.collection.JavaConverters._ import scala.concurrent.duration._ @@ -106,6 +109,13 @@ class AhcWSRequestSpec extends Specification with Mockito with AfterAll with Def } + "uri should not throw" in { + withClient { client => + val req = client.url("https://github.com/playframework/play-ws/issues/267/?pipe=|") + req.uri must not(throwAn[URISyntaxException]) + } + }.pendingUntilFixed("issue #267") + } "For Cookies" in {