Skip to content

fix: add cross-platform path validation and graceful error handling#52

Open
samalbishnupriya06-stack wants to merge 1 commit into
Kanwaljeet1:mainfrom
samalbishnupriya06-stack:fix/input-validation-path-handling
Open

fix: add cross-platform path validation and graceful error handling#52
samalbishnupriya06-stack wants to merge 1 commit into
Kanwaljeet1:mainfrom
samalbishnupriya06-stack:fix/input-validation-path-handling

Conversation

@samalbishnupriya06-stack
Copy link
Copy Markdown

Summary

Addresses the input validation and cross-platform path handling issue.
The tool previously risked crashes on malformed paths or mismatched OS separators.

Changes Made

Backend (src-tauri/src/main.rs)

  • Added validate_path() helper using std::path::Path for OS-agnostic path resolution
  • Added path traversal protection (../ stripping)
  • Wrapped all fs:: operations with match e.kind() to return human-readable errors instead of panics
  • Added explicit checks for: empty input, non-existent paths, permission errors, not-a-directory/file

Frontend (src/utils/pathValidator.ts) — New file

  • Client-side validation layer before any invoke() call
  • Detects Windows vs Unix paths via heuristics
  • Rejects: empty strings, null bytes, Windows invalid chars, path traversal

Frontend (src/services/optimizer.ts)

  • All Tauri invocations now validate + normalize paths first
  • Errors surfaced from Rust are caught and re-thrown as readable Error objects

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature
  • Improvement (code quality / stability)

How to Test

  1. Run npm run tauri dev
  2. Enter an invalid path like ../../etc/passwd → should show validation error, not crash
  3. Enter a non-existent path → should show "Path does not exist" message
  4. Test on both Windows and macOS/Linux — path separators should be handled correctly

Checklist

  • Code follows the project's TypeScript + Rust style guides
  • cargo check passes with no errors
  • npm run type-check passes
  • Tests added (can be added in follow-up if test suite is set up)
  • No breaking changes to existing API surface

Related Issue

Closes #34

- Add validate_path() helper in Rust backend using std::path
- Wrap all file system commands with OS-aware error messages
- Create src/utils/pathValidator.ts for frontend input validation
- Normalize path separators before invoking Tauri commands
- Replace raw stack traces with user-friendly error strings

Closes Kanwaljeet1#34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Add Input Validation and Cross-Platform Path Handling

1 participant