* encodeurlcomponent not working

* encoded files are loaded and getting rid of comments

* moving logic to asset service

* add encoded name test

* remove unused code

* remove comments

* remove console statements

* proper test and regex

* fix lintint errors
This commit is contained in:
Elizabeth Halper 2019-02-01 15:37:40 -08:00 коммит произвёл Wallace Breza
Родитель d03f561edc
Коммит db9176097e
3 изменённых файлов: 39 добавлений и 16 удалений

30
package-lock.json сгенерированный
Просмотреть файл

@ -1477,7 +1477,7 @@
"ansi-escapes": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz",
"integrity": "sha1-9zIHu4EgfXX9bIPxJa8m7qN4yjA="
"integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw=="
},
"ansi-html": {
"version": "0.0.7",
@ -3251,7 +3251,7 @@
},
"camelcase-keys": {
"version": "2.1.0",
"resolved": "http://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
"resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
"integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=",
"dev": true,
"requires": {
@ -8362,7 +8362,7 @@
},
"http-errors": {
"version": "1.6.3",
"resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
"integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=",
"requires": {
"depd": "~1.1.2",
@ -8964,7 +8964,7 @@
},
"is-builtin-module": {
"version": "1.0.0",
"resolved": "http://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz",
"resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz",
"integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=",
"requires": {
"builtin-modules": "^1.0.0"
@ -10412,7 +10412,7 @@
},
"load-json-file": {
"version": "1.1.0",
"resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
"requires": {
"graceful-fs": "^4.1.2",
@ -10834,7 +10834,7 @@
},
"meow": {
"version": "3.7.0",
"resolved": "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
"resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
"integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=",
"dev": true,
"requires": {
@ -11429,7 +11429,7 @@
},
"chalk": {
"version": "1.1.3",
"resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"dev": true,
"requires": {
@ -11470,7 +11470,7 @@
"dependencies": {
"colors": {
"version": "0.5.1",
"resolved": "http://registry.npmjs.org/colors/-/colors-0.5.1.tgz",
"resolved": "https://registry.npmjs.org/colors/-/colors-0.5.1.tgz",
"integrity": "sha1-fQAj6usVTo7p/Oddy5I9DtFmd3Q=",
"dev": true
}
@ -11826,7 +11826,7 @@
},
"os-tmpdir": {
"version": "1.0.2",
"resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
},
"osenv": {
@ -12029,7 +12029,7 @@
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"path-is-inside": {
@ -12090,7 +12090,7 @@
},
"pify": {
"version": "2.3.0",
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
},
"pinkie": {
@ -12554,7 +12554,7 @@
"dependencies": {
"async": {
"version": "1.5.2",
"resolved": "http://registry.npmjs.org/async/-/async-1.5.2.tgz",
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz",
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo="
},
"debug": {
@ -15733,7 +15733,7 @@
"dependencies": {
"jsesc": {
"version": "0.5.0",
"resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
"integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0="
}
}
@ -15862,7 +15862,7 @@
},
"require-uncached": {
"version": "1.0.3",
"resolved": "http://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
"resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
"integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=",
"requires": {
"caller-path": "^0.1.0",
@ -17367,7 +17367,7 @@
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": {
"ansi-regex": "^2.0.0"

Просмотреть файл

@ -19,6 +19,18 @@ describe("Asset Service", () => {
expect(asset.format).toEqual("jpg");
});
it("creates an asset from an encoded file", () => {
const path = "C:\\dir1\\dir2\\asset%201.jpg";
const asset = AssetService.createAssetFromFilePath(path);
expect(asset).not.toBeNull();
expect(asset.id).toEqual(expect.any(String));
expect(asset.name).toEqual("asset%201.jpg");
expect(asset.type).toEqual(AssetType.Image);
expect(asset.path).toEqual(path);
expect(asset.format).toEqual("jpg");
});
it("creates an asset from a http source", () => {
const path = "http://my.server.com/asset1.jpg";
const asset = AssetService.createAssetFromFilePath(path);
@ -120,6 +132,15 @@ describe("Asset Service", () => {
);
expect(result).toBe(assetMetadata);
});
it("getAssets encodes local file path", async () => {
const testAsset = MockFactory.createTestAsset(" 11");
testAssets.push(testAsset);
const result = await assetService.getAssets();
expect(result[10].path).toEqual("file:C:/Desktop/asset%2011.jpg");
});
});
describe("Assets Protocol Tests", () => {
@ -157,7 +178,7 @@ describe("Asset Service", () => {
const assets = await assetService.getAssets();
expect(assets.length).toEqual(2);
expect(assets[0].path).toEqual("file:C:\\Desktop\\asset0.jpg");
expect(assets[0].path).toEqual("file:C:/Desktop/asset0.jpg");
expect(assets[1].path).toEqual("https://image.com/asset1.jpg");
});

Просмотреть файл

@ -1,5 +1,6 @@
import MD5 from "md5.js";
import Guard from "../common/guard";
import path from "path";
import { IAsset, AssetType, IProject, IAssetMetadata, AssetState } from "../models/applicationState";
import { AssetProviderFactory, IAssetProvider } from "../providers/storage/assetProviderFactory";
import { StorageProviderFactory, IStorageProvider } from "../providers/storage/storageProviderFactory";
@ -107,6 +108,7 @@ export class AssetService {
return assets.map((asset) => {
if (!asset.path.toLowerCase().startsWith("http://") && !asset.path.toLowerCase().startsWith("https://")) {
asset.path = "file:" + asset.path;
asset.path = encodeURI(asset.path.replace(/\\/g, "/"));
}
return asset;