Skip to content
Merged
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
5 changes: 5 additions & 0 deletions crates/tinytools-std/src/filesystem/run_linter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ impl Tool for RunLinterTool {
(no absolute paths or '..')",
));
}
// A value starting with `-` would reach eslint as an option
// (`--output-file=<f>` writes a file). No path needs one.
if path.starts_with('-') {
return Ok(ToolResult::error("path must be a path, not an option"));
}
let mut cmd = tokio::process::Command::new("npx");
cmd.args(["eslint", "--format", "compact", path])
.current_dir(&workspace_dir);
Expand Down
15 changes: 15 additions & 0 deletions crates/tinytools-std/src/filesystem/run_linter/mod_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,18 @@ async fn a_workspace_descriptor_overrides_the_configured_directory() {
assert!(result.is_error);
assert!(result.output().contains("Could not detect project type"));
}

// A path starting with `-` would reach eslint as an option
// (`--output-file=<f>` writes a file). No path needs a leading `-`.
#[tokio::test]
async fn eslint_rejects_an_option_shaped_path() {
let tmp = TempDir::new().unwrap();
std::fs::write(tmp.path().join("package.json"), "{}").unwrap();
let result = make_tool(&tmp)
.execute(json!({"linter": "eslint", "path": "--output-file=pwned.txt"}))
.await
.unwrap();
assert!(result.is_error);
assert!(result.output().contains("not an option"));
assert!(!tmp.path().join("pwned.txt").exists());
}
Loading