File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -440,6 +440,22 @@ describe('Lib Functions', () => {
440440 ) ;
441441 } ) ;
442442
443+ it ( 'treats dollar signs in replacement text literally' , async ( ) => {
444+ const edits = [
445+ { oldText : 'line2' , newText : "price=$$; match=$&; before=$`; after=$'" }
446+ ] ;
447+
448+ mockFs . rename . mockResolvedValueOnce ( undefined ) ;
449+
450+ await applyFileEdits ( '/test/file.txt' , edits , false ) ;
451+
452+ expect ( mockFs . writeFile ) . toHaveBeenCalledWith (
453+ expect . stringMatching ( / \/ t e s t \/ f i l e \. t x t \. [ a - f 0 - 9 ] + \. t m p $ / ) ,
454+ "line1\nprice=$$; match=$&; before=$`; after=$'\nline3\n" ,
455+ 'utf-8'
456+ ) ;
457+ } ) ;
458+
443459 it ( 'handles dry run mode' , async ( ) => {
444460 const edits = [
445461 { oldText : 'line2' , newText : 'modified line2' }
Original file line number Diff line number Diff line change @@ -207,7 +207,7 @@ export async function applyFileEdits(
207207
208208 // If exact match exists, use it
209209 if ( modifiedContent . includes ( normalizedOld ) ) {
210- modifiedContent = modifiedContent . replace ( normalizedOld , normalizedNew ) ;
210+ modifiedContent = modifiedContent . replace ( normalizedOld , ( ) => normalizedNew ) ;
211211 continue ;
212212 }
213213
You can’t perform that action at this time.
0 commit comments