From 8cf2fbf16cad138d3092dfbe57bc6d109e78a56a Mon Sep 17 00:00:00 2001 From: Oleg Aleynik Date: Thu, 10 Dec 2015 12:04:21 -0800 Subject: [PATCH 1/2] fix(Path) replace space in path with the '+' Closes #7 --- src/imgix-core-js.js | 3 +++ test/test-path.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/imgix-core-js.js b/src/imgix-core-js.js index 0a4f08b0..5fd7790d 100644 --- a/src/imgix-core-js.js +++ b/src/imgix-core-js.js @@ -16,6 +16,9 @@ export class Path { // We are dealing with a fully-qualified URL as a path, encode it if (this.path.indexOf("http") === 0) { this.path = URI.encode(this.path); + } else { + // Replace spaces in path with '+' + this.path = this.path.replace(/ /g, "+"); } if (this.path[0] !== "/") { diff --git a/test/test-path.js b/test/test-path.js index 43369b99..b3da90e7 100644 --- a/test/test-path.js +++ b/test/test-path.js @@ -28,6 +28,11 @@ describe('Path', () => { assert.equal(path.toString(), "http://my-source.imgix.net/path/to/image.png"); }); + it('encodes with the space in path correctly', () => { + let path = new Path('/users/image 1.png', 'my-social-network.imgix.net', 'FOO123bar', true, null); + assert.equal(path.toString(), "https://my-social-network.imgix.net/users/image+1.png?s=9254fd1082fa408fd7cc7c0b0f651cc2"); + }); + it('encodes with a token correctly', () => { let path = new Path('/users/1.png', 'my-social-network.imgix.net', 'FOO123bar', true, null); assert.equal(path.toString(), "https://my-social-network.imgix.net/users/1.png?s=6797c24146142d5b40bde3141fd3600c"); From 49bd9a8ba6bfc7fb4c2a23db66168cb8e3940fc5 Mon Sep 17 00:00:00 2001 From: Oleg Aleynik Date: Fri, 11 Dec 2015 12:42:41 -0800 Subject: [PATCH 2/2] fix(Path) use URI.encodeReserved instead of direct string manipulation --- src/imgix-core-js.js | 2 +- test/test-path.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/imgix-core-js.js b/src/imgix-core-js.js index 5fd7790d..22e8d1e3 100644 --- a/src/imgix-core-js.js +++ b/src/imgix-core-js.js @@ -18,7 +18,7 @@ export class Path { this.path = URI.encode(this.path); } else { // Replace spaces in path with '+' - this.path = this.path.replace(/ /g, "+"); + this.path = URI.encodeReserved(this.path); } if (this.path[0] !== "/") { diff --git a/test/test-path.js b/test/test-path.js index b3da90e7..6a17c254 100644 --- a/test/test-path.js +++ b/test/test-path.js @@ -30,7 +30,7 @@ describe('Path', () => { it('encodes with the space in path correctly', () => { let path = new Path('/users/image 1.png', 'my-social-network.imgix.net', 'FOO123bar', true, null); - assert.equal(path.toString(), "https://my-social-network.imgix.net/users/image+1.png?s=9254fd1082fa408fd7cc7c0b0f651cc2"); + assert.equal(path.toString(), "https://my-social-network.imgix.net/users/image%201.png?s=193462f12470fe53927d0cf21e07d404"); }); it('encodes with a token correctly', () => {