From fd4ccc846bcf882f46f451d8138d2c3e2467c6d1 Mon Sep 17 00:00:00 2001 From: Shashwat Chaturvedi Date: Fri, 18 Aug 2017 09:49:23 -0700 Subject: [PATCH 1/2] Support view mode import --- src/client/app/effects/snippet.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/client/app/effects/snippet.ts b/src/client/app/effects/snippet.ts index e87f7c9a..a2305c9d 100644 --- a/src/client/app/effects/snippet.ts +++ b/src/client/app/effects/snippet.ts @@ -198,7 +198,7 @@ export class SnippetEffects { .catch(exception => Observable.of(new UI.ReportErrorAction(Strings().snippetUpdateError, exception))); private _gistIdExists(id: string) { - return storage.snippets.values().some(item => item.gist.trim() === id.trim()); + return storage.snippets.values().some(item => item.gist && item.gist.trim() === id.trim()); } private _nameExists(name: string) { @@ -288,6 +288,12 @@ export class SnippetEffects { case Snippet.ImportType.SAMPLE: case Snippet.ImportType.URL: case Snippet.ImportType.GIST: + if (type === Snippet.ImportType.URL && /#\/view/.test(data)) { + /* If importing from a view-mode URL, simply redirect the user */ + window.location.href = data; + } + + let id = null; const match = /https:\/\/gist.github.com\/(?:.*?\/|.*?)([a-z0-9]{32})$/.exec(data); From 32e24f1226cbce8aea9e0e28a20a232fcb3fa41f Mon Sep 17 00:00:00 2001 From: Shashwat Chaturvedi Date: Fri, 18 Aug 2017 10:33:54 -0700 Subject: [PATCH 2/2] Add more robust regex --- src/client/app/effects/snippet.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/app/effects/snippet.ts b/src/client/app/effects/snippet.ts index a2305c9d..bd0f7791 100644 --- a/src/client/app/effects/snippet.ts +++ b/src/client/app/effects/snippet.ts @@ -288,7 +288,8 @@ export class SnippetEffects { case Snippet.ImportType.SAMPLE: case Snippet.ImportType.URL: case Snippet.ImportType.GIST: - if (type === Snippet.ImportType.URL && /#\/view/.test(data)) { + let viewUrlMatch = new RegExp(`^${environment.current.config.editorUrl}\/#\/view`); + if (type === Snippet.ImportType.URL && viewUrlMatch.test(data)) { /* If importing from a view-mode URL, simply redirect the user */ window.location.href = data; }