@@ -72,7 +72,35 @@ test('simple case', (assert) => {
7272 } , 1 ) ;
7373} ) ;
7474
75- test ( 'simple case - check if quotes are correctly escaped' , ( assert ) => {
75+ test ( 'simple case - should not throw error when pattern and replacement are not provided' , ( assert ) => {
76+ const done = assert . async ( ) ;
77+
78+ const nodeName = 'div' ;
79+ const textMatch = 'qwerty!' ;
80+
81+ const text = 'qwerty!1' ;
82+ const expectedText = 'qwerty!1' ;
83+
84+ const nodeBefore = addNode ( 'div' , text ) ;
85+ const safeNodeBefore = addNode ( 'a' , text ) ;
86+
87+ runScriptlet ( name , [ nodeName , textMatch ] ) ;
88+
89+ const nodeAfter = addNode ( 'div' , text ) ;
90+ const safeNodeAfter = addNode ( 'span' , text ) ;
91+ setTimeout ( ( ) => {
92+ assert . strictEqual ( nodeAfter . textContent , expectedText , 'text content should not be modified' ) ;
93+ assert . strictEqual ( nodeBefore . textContent , expectedText , 'text content should not be modified' ) ;
94+
95+ assert . strictEqual ( safeNodeAfter . textContent , text , 'non-matched node should not be affected' ) ;
96+ assert . strictEqual ( safeNodeBefore . textContent , text , 'non-matched node should not be affected' ) ;
97+
98+ assert . strictEqual ( window . hit , 'FIRED' , 'hit function should fire' ) ;
99+ done ( ) ;
100+ } , 1 ) ;
101+ } ) ;
102+
103+ test ( 'simple case - check if quotes are correctly escaped in pattern and replacement' , ( assert ) => {
76104 const done = assert . async ( ) ;
77105
78106 const nodeName = 'div' ;
@@ -101,6 +129,35 @@ test('simple case - check if quotes are correctly escaped', (assert) => {
101129 } , 1 ) ;
102130} ) ;
103131
132+ test ( 'simple case - check if quotes are correctly escaped in result' , ( assert ) => {
133+ const done = assert . async ( ) ;
134+
135+ const nodeName = 'div' ;
136+ const textMatch = 'alert' ;
137+ const pattern = 'foo' ;
138+ const replacement = 'bar' ;
139+ const text = 'alert("\\"foo\\"")' ;
140+ const expectedText = 'alert("\\"bar\\"")' ;
141+
142+ const nodeBefore = addNode ( 'div' , text ) ;
143+ const safeNodeBefore = addNode ( 'a' , text ) ;
144+
145+ runScriptlet ( name , [ nodeName , textMatch , pattern , replacement ] ) ;
146+
147+ const nodeAfter = addNode ( 'div' , text ) ;
148+ const safeNodeAfter = addNode ( 'span' , text ) ;
149+ setTimeout ( ( ) => {
150+ assert . strictEqual ( nodeAfter . textContent , expectedText , 'text content should be modified' ) ;
151+ assert . strictEqual ( nodeBefore . textContent , expectedText , 'text content should be modified' ) ;
152+
153+ assert . strictEqual ( safeNodeAfter . textContent , text , 'non-matched node should not be affected' ) ;
154+ assert . strictEqual ( safeNodeBefore . textContent , text , 'non-matched node should not be affected' ) ;
155+
156+ assert . strictEqual ( window . hit , 'FIRED' , 'hit function should fire' ) ;
157+ done ( ) ;
158+ } , 1 ) ;
159+ } ) ;
160+
104161test ( 'using matchers as regexes' , ( assert ) => {
105162 const done = assert . async ( ) ;
106163
0 commit comments