From 13ad97b267070496bb166f4c879d7764365437c5 Mon Sep 17 00:00:00 2001 From: William Lachance Date: Tue, 3 Mar 2020 13:37:26 -0500 Subject: [PATCH] Fix plugin cells (#2721) Plugin cells have no variable type, but #2475 (accidentally) added checking for that nonetheless. --- CHANGELOG.md | 1 + .../actions/__tests__/fetch-cell-parser.test.js | 10 ++++++++++ src/editor/actions/fetch-cell-parser.js | 13 ++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31df4337cf..f9e0bacf89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Can now specify notebook iomd via a URL parameter with new or tryit endpoints (fixes #2565) (#2676) - Always show "Clear history" button in the Console dropdown (#2707) +- Fix plugin cell parsing (#2721) # 0.18.0 (2020-01-22) diff --git a/src/editor/actions/__tests__/fetch-cell-parser.test.js b/src/editor/actions/__tests__/fetch-cell-parser.test.js index eb5ccce0bf..300a673d71 100644 --- a/src/editor/actions/__tests__/fetch-cell-parser.test.js +++ b/src/editor/actions/__tests__/fetch-cell-parser.test.js @@ -173,6 +173,16 @@ const validFetchLines = [ filePath: "https://d3js.org/d3.v5.min.js", isRelPath: false } + }, + { + line: + "plugin: https://raw.githubusercontent.com/iodide-project/iodide-mermaid-plugin/master/plugin.json", + result: { + fetchType: "plugin", + filePath: + "https://raw.githubusercontent.com/iodide-project/iodide-mermaid-plugin/master/plugin.json", + isRelPath: false + } } ]; describe("return valid results for valid fetch lines", () => { diff --git a/src/editor/actions/fetch-cell-parser.js b/src/editor/actions/fetch-cell-parser.js index 03321f2fff..c84a098af3 100644 --- a/src/editor/actions/fetch-cell-parser.js +++ b/src/editor/actions/fetch-cell-parser.js @@ -60,9 +60,16 @@ export function missingFetchType(line) { return !line.trim().match(/^\w+\s*: /); } +function getFetchType(line) { + return line + .trim() + .split(": ")[0] + .trimLeft(); +} + export function validFetchType(line) { - const fetchType = line.trim().split(": ")[0]; - return VALID_FETCH_TYPES.includes(fetchType.trimLeft()); + const fetchType = getFetchType(line); + return VALID_FETCH_TYPES.includes(fetchType); } export function validVariableName(line) { @@ -138,7 +145,7 @@ export function parseFetchCellLine(lineWithComments) { if (!validFetchUrl(line)) { return { error: "INVALID_FETCH_URL" }; } - if (!validVariableName(line)) { + if (getFetchType(line) !== "plugin" && !validVariableName(line)) { return { error: "INVALID_VARIABLE_NAME" }; }