@@ -172,10 +172,11 @@ impl FsWrite {
172
172
match self {
173
173
FsWrite :: Create { path, .. } => {
174
174
let file_text = self . canonical_create_command_text ( ) ;
175
- let relative_path = format_path ( cwd, path) ;
176
- let prev = if ctx. fs . exists ( path) {
177
- let file = ctx. fs . read_to_string_sync ( path) ?;
178
- stylize_output_if_able ( ctx, path, & file)
175
+ let path = sanitize_path_tool_arg ( ctx, path) ;
176
+ let relative_path = format_path ( cwd, & path) ;
177
+ let prev = if ctx. fs . exists ( & path) {
178
+ let file = ctx. fs . read_to_string_sync ( & path) ?;
179
+ stylize_output_if_able ( ctx, & path, & file)
179
180
} else {
180
181
Default :: default ( )
181
182
} ;
@@ -188,8 +189,9 @@ impl FsWrite {
188
189
insert_line,
189
190
new_str,
190
191
} => {
191
- let relative_path = format_path ( cwd, path) ;
192
- let file = ctx. fs . read_to_string_sync ( & relative_path) ?;
192
+ let path = sanitize_path_tool_arg ( ctx, path) ;
193
+ let relative_path = format_path ( cwd, & path) ;
194
+ let file = ctx. fs . read_to_string_sync ( & path) ?;
193
195
194
196
// Diff the old with the new by adding extra context around the line being inserted
195
197
// at.
@@ -207,8 +209,9 @@ impl FsWrite {
207
209
Ok ( ( ) )
208
210
} ,
209
211
FsWrite :: StrReplace { path, old_str, new_str } => {
210
- let relative_path = format_path ( cwd, path) ;
211
- let file = ctx. fs . read_to_string_sync ( & relative_path) ?;
212
+ let path = sanitize_path_tool_arg ( ctx, path) ;
213
+ let relative_path = format_path ( cwd, & path) ;
214
+ let file = ctx. fs . read_to_string_sync ( & path) ?;
212
215
let ( start_line, _) = match line_number_at ( & file, old_str) {
213
216
Some ( ( start_line, end_line) ) => ( start_line, end_line) ,
214
217
_ => ( 0 , 0 ) ,
@@ -220,8 +223,9 @@ impl FsWrite {
220
223
Ok ( ( ) )
221
224
} ,
222
225
FsWrite :: Append { path, new_str } => {
223
- let relative_path = format_path ( cwd, path) ;
224
- let start_line = ctx. fs . read_to_string_sync ( & relative_path) ?. lines ( ) . count ( ) + 1 ;
226
+ let path = sanitize_path_tool_arg ( ctx, path) ;
227
+ let relative_path = format_path ( cwd, & path) ;
228
+ let start_line = ctx. fs . read_to_string_sync ( & path) ?. lines ( ) . count ( ) + 1 ;
225
229
let file = stylize_output_if_able ( ctx, & relative_path, new_str) ;
226
230
print_diff ( output, & Default :: default ( ) , & file, start_line) ?;
227
231
Ok ( ( ) )
0 commit comments