validateInput method

  1. @override
ValidationResult validateInput(
  1. Map<String, dynamic> input
)
override

Validate input before execution and permission checks.

Implementation

@override
ValidationResult validateInput(Map<String, dynamic> input) {
  final pattern = input['pattern'] as String?;
  if (pattern == null || pattern.isEmpty) {
    return const ValidationResult.invalid(
      'Missing required parameter: pattern',
    );
  }

  // If path is provided, validate it exists
  final path = input['path'] as String?;
  if (path != null && path.isNotEmpty) {
    final absolutePath = expandPath(path);

    // SECURITY: Skip filesystem operations for UNC paths to prevent
    // NTLM credential leaks.
    if (absolutePath.startsWith('\\\\') || absolutePath.startsWith('//')) {
      return const ValidationResult.valid();
    }

    final entity = FileSystemEntity.typeSync(absolutePath);
    if (entity == FileSystemEntityType.notFound) {
      return ValidationResult.invalid(
        'Path does not exist: $path. '
        'Current working directory is ${Directory.current.path}.',
      );
    }
  }

  return const ValidationResult.valid();
}