@@ -550,6 +550,28 @@ def test_returns_ajax_errors(self, basket_mock):
550550 self .assertIn ('privacy' , resp_data ['errors' ][0 ])
551551 self .assertFalse (basket_mock .called )
552552
553+ @patch ('bedrock.newsletter.views.basket' )
554+ def test_returns_sanitized_ajax_errors (self , basket_mock ):
555+ """Error messages should be HTML escaped.
556+
557+ Bug 1116754
558+ """
559+ data = {
560+ 'newsletters' : 'flintstones' ,
561+ 'email' : 'fred@example.com' ,
562+ 'fmt' : 'H' ,
563+ 'privacy' : True ,
564+ 'country' : '<svg/onload=alert("NEFARIOUSNESS")>' ,
565+ }
566+ resp = self .ajax_request (data )
567+ resp_data = json .loads (resp .content )
568+ self .assertFalse (resp_data ['success' ])
569+ self .assertEqual (len (resp_data ['errors' ]), 1 )
570+ self .assertNotIn (data ['country' ], resp_data ['errors' ][0 ])
571+ self .assertIn ('NEFARIOUSNESS' , resp_data ['errors' ][0 ])
572+ self .assertIn ('<svg' , resp_data ['errors' ][0 ])
573+ self .assertFalse (basket_mock .called )
574+
553575 @patch ('bedrock.newsletter.views.basket' )
554576 def test_returns_ajax_success (self , basket_mock ):
555577 """Good post should return success JSON"""
0 commit comments