Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion js/terminal-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,13 @@ const extend = (term) => {
// directly rather than executeCommandLine for exactly this reason.
term.runDeepLink = ({ replay = false } = {}) => {
if (term.deepLink != "") {
term.executeCommandLine(term.deepLink, {
const parsed = term.parseCommandLine(term.deepLink);

if (parsed.cmd === "eval" && window.confirm(parsed.line) !== true) {
return;
}

term.executeCommandLine(parsed.line, {
addToHistory: false,
promptAfter: false,
showLeadingNewline: false,
Expand Down
38 changes: 38 additions & 0 deletions tests/terminal-ext.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,44 @@ describe("terminal-ext", () => {
);
});

it("requires exact confirmation before dispatching an eval deep link", () => {
const confirm = vi
.fn()
.mockReturnValueOnce(false)
.mockReturnValueOnce(undefined)
.mockReturnValueOnce(true)
.mockReturnValueOnce(true);
const { extend } = loadTerminalExt({ confirm });
env.window.location.hash = "#eval-alert(1)";
const term = createTerm();

extend(term);
term.executeCommandLine = vi.fn(() => Promise.resolve());

term.runDeepLink();
term.runDeepLink({ replay: true });
term.runDeepLink();
term.runDeepLink({ replay: true });

expect(confirm).toHaveBeenNthCalledWith(1, "eval alert(1)");
expect(confirm).toHaveBeenNthCalledWith(2, "eval alert(1)");
expect(confirm).toHaveBeenNthCalledWith(3, "eval alert(1)");
expect(confirm).toHaveBeenNthCalledWith(4, "eval alert(1)");
expect(term.executeCommandLine).toHaveBeenCalledTimes(2);
expect(term.executeCommandLine).toHaveBeenNthCalledWith(1, "eval alert(1)", {
addToHistory: false,
promptAfter: false,
showLeadingNewline: false,
trackAnalytics: true,
});
expect(term.executeCommandLine).toHaveBeenNthCalledWith(2, "eval alert(1)", {
addToHistory: false,
promptAfter: false,
showLeadingNewline: false,
trackAnalytics: false,
});
});

it.each([
["#jobs", "jobs"],
["#whois-root", "whois root"],
Expand Down
Loading