From 73bb62263cd5f5ce8555951b98eefe77f914a282 Mon Sep 17 00:00:00 2001 From: ewestra Date: Wed, 19 Feb 2014 10:06:08 +0100 Subject: [PATCH] Fixed a problem in the S3Signer regarding escaped url's. fixes #19 --- app/fly/play/s3/S3Signer.scala | 6 +++--- project/Build.scala | 2 +- test/fly/play/s3/S3Spec.scala | 26 +++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/fly/play/s3/S3Signer.scala b/app/fly/play/s3/S3Signer.scala index 50bb69e..48dd991 100644 --- a/app/fly/play/s3/S3Signer.scala +++ b/app/fly/play/s3/S3Signer.scala @@ -3,7 +3,6 @@ package fly.play.s3 import java.net.URI import java.security.MessageDigest import java.util.Date - import fly.play.aws.Aws.dates.rfc822DateFormat import fly.play.aws.auth.AwsCredentials import fly.play.aws.auth.Signer @@ -13,6 +12,7 @@ import javax.crypto.spec.SecretKeySpec import play.api.http.ContentTypeOf import play.api.http.Writeable import play.api.libs.ws.WS +import java.net.URL case class S3Signer(credentials: AwsCredentials, s3Host: String) extends Signer with SignerUtils { private val AwsCredentials(accessKeyId, secretKey, sessionToken, expirationSeconds) = credentials @@ -47,8 +47,8 @@ case class S3Signer(credentials: AwsCredentials, s3Host: String) extends Signer var newHeaders = addHeaders(request.headers, dateTime, contentType, contentMd5) - val uri = URI.create(request.url) - var path = uri.getPath match { + val uri = new URL(request.url) + val path = uri.getPath match { case "" | null => None case path => Some(path) } diff --git a/project/Build.scala b/project/Build.scala index 83f7168..ff4f02c 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -5,7 +5,7 @@ import play.Project._ object ApplicationBuild extends Build { val appName = "play-s3" - val appVersion = "3.3.3" + val appVersion = "3.3.4" val appDependencies = Seq( "nl.rhinofly" %% "play-aws-utils" % "2.4.2") diff --git a/test/fly/play/s3/S3Spec.scala b/test/fly/play/s3/S3Spec.scala index a5c33c4..c72f11f 100644 --- a/test/fly/play/s3/S3Spec.scala +++ b/test/fly/play/s3/S3Spec.scala @@ -3,18 +3,15 @@ package fly.play.s3 import java.io.File import java.lang.IllegalArgumentException import java.util.Date - import scala.concurrent.Await import scala.concurrent.Awaitable import scala.concurrent.Future import scala.concurrent.duration.Duration import scala.util.Failure import scala.util.Success - import org.specs2.execute.AsResult import org.specs2.mutable.Specification import org.specs2.specification.Example - import fly.play.aws.auth.SimpleAwsCredentials import fly.play.s3.acl.CanonicalUser import fly.play.s3.acl.FULL_CONTROL @@ -32,6 +29,7 @@ import play.api.libs.ws.WS import play.api.test.FakeApplication import play.api.test.Helpers.running import utils.MultipartFormData +import java.net.URLEncoder class S3Spec extends Specification { @@ -403,6 +401,28 @@ class S3Spec extends Specification { noException(testBucket remove expectedFileName) } + + } + + "be able to add and delete files with 'weird' names" inApp { + + def uploadListAndRemoveFileWithName(prefix:String, name: String) = { + await(testBucket + BucketFile(URLEncoder.encode(prefix + name, "UTF-8"), "text/plain", "test".getBytes)) + + await(testBucket.list(prefix)) must beLike { + case Seq(BucketItem(itemName, false)) => itemName === (prefix + name) + } + + await(testBucket - URLEncoder.encode(prefix + name, "UTF-8")) + + success + } + + uploadListAndRemoveFileWithName("sample/", "test file.txt") + uploadListAndRemoveFileWithName("sample/", "test&;-file.txt") + uploadListAndRemoveFileWithName("sample/", "test & file.txt") + uploadListAndRemoveFileWithName("sample/", "test+&+file.txt") } } + }