@@ -373,6 +373,58 @@ public function testSaveAndClose()
373373 $ this ->assertSame ($ this ->resultRedirect , $ this ->saveController ->execute ());
374374 }
375375
376+ public function testSaveActionWithMarginalSpace ()
377+ {
378+ $ postData = [
379+ 'title ' => '"><img src=y onerror=prompt(document.domain)>; ' ,
380+ 'identifier ' => ' unique_title_123 ' ,
381+ 'stores ' => ['0 ' ],
382+ 'is_active ' => true ,
383+ 'content ' => '"><script>alert("cookie: "+document.cookie)</script> ' ,
384+ 'back ' => 'continue '
385+ ];
386+
387+ $ this ->requestMock ->expects ($ this ->any ())->method ('getPostValue ' )->willReturn ($ postData );
388+ $ this ->requestMock ->expects ($ this ->atLeastOnce ())
389+ ->method ('getParam ' )
390+ ->willReturnMap (
391+ [
392+ ['block_id ' , null , 1 ],
393+ ['back ' , null , true ],
394+ ]
395+ );
396+
397+ $ this ->blockFactory ->expects ($ this ->atLeastOnce ())
398+ ->method ('create ' )
399+ ->willReturn ($ this ->blockMock );
400+
401+ $ this ->blockRepository ->expects ($ this ->once ())
402+ ->method ('getById ' )
403+ ->with ($ this ->blockId )
404+ ->willReturn ($ this ->blockMock );
405+
406+ $ this ->blockMock ->expects ($ this ->once ())->method ('setData ' );
407+ $ this ->blockRepository ->expects ($ this ->once ())->method ('save ' )
408+ ->with ($ this ->blockMock )
409+ ->willThrowException (new \Exception ('No marginal white space please. ' ));
410+
411+ $ this ->messageManagerMock ->expects ($ this ->never ())
412+ ->method ('addSuccessMessage ' );
413+ $ this ->messageManagerMock ->expects ($ this ->once ())
414+ ->method ('addExceptionMessage ' );
415+
416+ $ this ->dataPersistorMock ->expects ($ this ->any ())
417+ ->method ('set ' )
418+ ->with ('cms_block ' , array_merge ($ postData , ['block_id ' => null ]));
419+
420+ $ this ->resultRedirect ->expects ($ this ->atLeastOnce ())
421+ ->method ('setPath ' )
422+ ->with ('*/*/edit ' , ['block_id ' => $ this ->blockId ])
423+ ->willReturnSelf ();
424+
425+ $ this ->assertSame ($ this ->resultRedirect , $ this ->saveController ->execute ());
426+ }
427+
376428 public function testSaveActionThrowsException ()
377429 {
378430 $ postData = [
0 commit comments