Skip to content

Commit 009dbf8

Browse files
URL encode (ä|ö|ü) in invalidation path
1 parent 2e53637 commit 009dbf8

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This project uses [Semantic Versioning](http://semver.org).
44

5+
## 2.8.5
6+
7+
* URL encode (ä|ö|ü) in invalidation path
8+
59
## 2.8.4
610

711
* URL encude ' in invalidation path

lib/s3_website/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module S3Website
2-
VERSION = '2.8.4'
2+
VERSION = '2.8.5'
33
end

src/main/scala/s3/website/CloudFront.scala

+9-2
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,16 @@ object CloudFront {
117117
def toInvalidationPath(report: PushSuccessReport) = "/" + report.s3Key
118118

119119
def encodeUnsafeChars(invalidationPath: String) =
120-
new URI("http", "cloudfront", invalidationPath, "").toURL.getPath
120+
new URI("http", "cloudfront", invalidationPath, "")
121+
.toURL
122+
.getPath
121123
.replaceAll("'", URLEncoder.encode("'", "UTF-8")) // CloudFront does not accept ' in invalidation path
122-
124+
.flatMap(chr => {
125+
if (Seq("ä", "ö", "ü").contains(chr.toString.toLowerCase))
126+
URLEncoder.encode(chr.toString, "UTF-8")
127+
else
128+
chr.toString
129+
})
123130

124131
def needsInvalidation: PartialFunction[PushSuccessReport, Boolean] = {
125132
case succ: SuccessfulUpload => succ.details.fold(_.uploadType, _.uploadType) == FileUpdate

src/test/scala/s3/website/S3WebsiteSpec.scala

+8
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ class S3WebsiteSpec extends Specification {
207207
sentInvalidationRequest.getInvalidationBatch.getPaths.getItems.toSeq.sorted must equalTo(("/articles/arnold%27s%20file.html" :: Nil).sorted)
208208
}
209209

210+
"encode unsafe characters in the keys" in new BasicSetup {
211+
config = "cloudfront_distribution_id: EGM1J2JJX9Z"
212+
setLocalFile("articles/Äöü.html")
213+
setOutdatedS3Keys("articles/Äöü.html")
214+
push()
215+
sentInvalidationRequest.getInvalidationBatch.getPaths.getItems.toSeq.sorted must equalTo(("/articles/%C3%84%C3%B6%C3%BC.html" :: Nil).sorted)
216+
}
217+
210218
"invalidate the root object '/' if a top-level object is updated or deleted" in new BasicSetup {
211219
config = "cloudfront_distribution_id: EGM1J2JJX9Z"
212220
setLocalFile("maybe-index.html")

0 commit comments

Comments
 (0)