'Special characters (e.g. %, _ and \) stored in database are
properly escaped when using a pattern lookup with an expression
refs #16731'

def test_patterns_escape(self):

    Employee.objects.bulk_create([Employee(firstname='%Joh\\nny', lastname='%Joh\\n'), Employee(firstname='Johnny', lastname='%John'), Employee(firstname='Jean-Claude', lastname='Claud_'), Employee(firstname='Jean-Claude', lastname='Claude'), Employee(firstname='Jean-Claude', lastname='Claude%'), Employee(firstname='Johnny', lastname='Joh\\n'), Employee(firstname='Johnny', lastname='John'), Employee(firstname='Johnny', lastname='_ohn')])
    self.assertQuerysetEqual(Employee.objects.filter(firstname__contains=F('lastname')), ['<Employee:    %Joh\\nny    %Joh\\n>', '<Employee:    Jean-Claude    Claude>', '<Employee:    Johnny    John>'], ordered=False)
    self.assertQuerysetEqual(Employee.objects.filter(firstname__startswith=F('lastname')), ['<Employee:    %Joh\\nny    %Joh\\n>', '<Employee:    Johnny    John>'], ordered=False)
    self.assertQuerysetEqual(Employee.objects.filter(firstname__endswith=F('lastname')), ['<Employee:    Jean-Claude    Claude>'], ordered=False)
