Skip to content

Commit

Permalink
Fix plugin cells (#2721)
Browse files Browse the repository at this point in the history
Plugin cells have no variable type, but #2475 (accidentally) added
checking for that nonetheless.
  • Loading branch information
wlach committed Mar 3, 2020
1 parent 1902e54 commit 13ad97b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions src/editor/actions/__tests__/fetch-cell-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
13 changes: 10 additions & 3 deletions src/editor/actions/fetch-cell-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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" };
}

Expand Down

0 comments on commit 13ad97b

Please sign in to comment.