Skip to content
This repository was archived by the owner on Nov 20, 2019. It is now read-only.

Commit 73bb622

Browse files
committed
Fixed a problem in the S3Signer regarding escaped url's. fixes #19
1 parent 52dcc7b commit 73bb622

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

app/fly/play/s3/S3Signer.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package fly.play.s3
33
import java.net.URI
44
import java.security.MessageDigest
55
import java.util.Date
6-
76
import fly.play.aws.Aws.dates.rfc822DateFormat
87
import fly.play.aws.auth.AwsCredentials
98
import fly.play.aws.auth.Signer
@@ -13,6 +12,7 @@ import javax.crypto.spec.SecretKeySpec
1312
import play.api.http.ContentTypeOf
1413
import play.api.http.Writeable
1514
import play.api.libs.ws.WS
15+
import java.net.URL
1616

1717
case class S3Signer(credentials: AwsCredentials, s3Host: String) extends Signer with SignerUtils {
1818
private val AwsCredentials(accessKeyId, secretKey, sessionToken, expirationSeconds) = credentials
@@ -47,8 +47,8 @@ case class S3Signer(credentials: AwsCredentials, s3Host: String) extends Signer
4747

4848
var newHeaders = addHeaders(request.headers, dateTime, contentType, contentMd5)
4949

50-
val uri = URI.create(request.url)
51-
var path = uri.getPath match {
50+
val uri = new URL(request.url)
51+
val path = uri.getPath match {
5252
case "" | null => None
5353
case path => Some(path)
5454
}

project/Build.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import play.Project._
55
object ApplicationBuild extends Build {
66

77
val appName = "play-s3"
8-
val appVersion = "3.3.3"
8+
val appVersion = "3.3.4"
99

1010
val appDependencies = Seq(
1111
"nl.rhinofly" %% "play-aws-utils" % "2.4.2")

test/fly/play/s3/S3Spec.scala

+23-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@ package fly.play.s3
33
import java.io.File
44
import java.lang.IllegalArgumentException
55
import java.util.Date
6-
76
import scala.concurrent.Await
87
import scala.concurrent.Awaitable
98
import scala.concurrent.Future
109
import scala.concurrent.duration.Duration
1110
import scala.util.Failure
1211
import scala.util.Success
13-
1412
import org.specs2.execute.AsResult
1513
import org.specs2.mutable.Specification
1614
import org.specs2.specification.Example
17-
1815
import fly.play.aws.auth.SimpleAwsCredentials
1916
import fly.play.s3.acl.CanonicalUser
2017
import fly.play.s3.acl.FULL_CONTROL
@@ -32,6 +29,7 @@ import play.api.libs.ws.WS
3229
import play.api.test.FakeApplication
3330
import play.api.test.Helpers.running
3431
import utils.MultipartFormData
32+
import java.net.URLEncoder
3533

3634
class S3Spec extends Specification {
3735

@@ -403,6 +401,28 @@ class S3Spec extends Specification {
403401

404402
noException(testBucket remove expectedFileName)
405403
}
404+
405+
}
406+
407+
"be able to add and delete files with 'weird' names" inApp {
408+
409+
def uploadListAndRemoveFileWithName(prefix:String, name: String) = {
410+
await(testBucket + BucketFile(URLEncoder.encode(prefix + name, "UTF-8"), "text/plain", "test".getBytes))
411+
412+
await(testBucket.list(prefix)) must beLike {
413+
case Seq(BucketItem(itemName, false)) => itemName === (prefix + name)
414+
}
415+
416+
await(testBucket - URLEncoder.encode(prefix + name, "UTF-8"))
417+
418+
success
419+
}
420+
421+
uploadListAndRemoveFileWithName("sample/", "test file.txt")
422+
uploadListAndRemoveFileWithName("sample/", "test&;-file.txt")
423+
uploadListAndRemoveFileWithName("sample/", "test & file.txt")
424+
uploadListAndRemoveFileWithName("sample/", "test+&+file.txt")
406425
}
407426
}
427+
408428
}

0 commit comments

Comments
 (0)