def testEscaping(self): # Test query escaping. self.assertEqual(escape_query(""), "") self.assertEqual(escape_query("abcd"), "abcd") self.assertEqual(escape_query("abcd efgh"), "abcd efgh") self.assertEqual(escape_query("abcd efgh"), "abcd efgh") self.assertEqual(escape_query("&&abcd&"), "abcd") # check if we leave good characters good_chars = "'$@#$^=_.," for char in good_chars: self.assertEqual(escape_query("abcd{}efgh".format(char)), "abcd{}efgh".format(char)) # now the ones where we replace harmful characters bad_chars = '&:"(|)!><~*+-' for char in bad_chars: self.assertEqual(escape_query("abcd{}efgh".format(char)), "abcd efgh")
def testEscaping(self): # Test query escaping. self.assertEqual(escape_query(""), "") self.assertEqual(escape_query("abcd"), "abcd") self.assertEqual(escape_query("abcd efgh"), "abcd efgh") self.assertEqual(escape_query("abcd efgh"), "abcd efgh") self.assertEqual(escape_query("&&abcd&"), "abcd") # check if we leave good characters good_chars = "'$@#$^=_.," for char in good_chars: self.assertEqual( escape_query("abcd{}efgh".format(char)), "abcd{}efgh".format(char) ) # now the ones where we replace harmful characters bad_chars = '&:"(|)!><~*+-' for char in bad_chars: self.assertEqual( escape_query("abcd{}efgh".format(char)), "abcd efgh" )
def escape_postgres_query(self, text): """Escapes the given text to become a valid ts_query.""" return " | ".join( "$${0}$$:*".format(word) for word in escape_query(text).split() )
def testEscaping(self): # Test query escaping. self.assertEqual(escape_query(""), "") self.assertEqual(escape_query("abcd"), "abcd") self.assertEqual(escape_query("abcd efgh"), "abcd efgh") self.assertEqual(escape_query("abcd efgh"), "abcd efgh") self.assertEqual(escape_query("abcd'efgh"), "abcd'efgh") self.assertEqual(escape_query("'abcd&efgh"), "'abcd&efgh") self.assertEqual(escape_query("abcd@efgh"), "abcd@efgh") self.assertEqual(escape_query("abcd#efgh"), "abcd#efgh") self.assertEqual(escape_query("abcd$efgh"), "abcd$efgh") self.assertEqual(escape_query("abcd^efgh"), "abcd^efgh") self.assertEqual(escape_query("abcd&efgh"), "abcd&efgh") self.assertEqual(escape_query("abcd*efgh"), "abcd*efgh") self.assertEqual(escape_query("abcd=efgh"), "abcd=efgh") self.assertEqual(escape_query("abcd+efgh"), "abcd+efgh") self.assertEqual(escape_query("abcd-efgh"), "abcd-efgh") self.assertEqual(escape_query("abcd_efgh"), "abcd_efgh") self.assertEqual(escape_query("abcd.efgh"), "abcd.efgh") self.assertEqual(escape_query("abcd,efgh"), "abcd,efgh") # now the ones where we replace harmful characters self.assertEqual(escape_query("&abcd"), "abcd") self.assertEqual(escape_query("&&&abcd"), "abcd") self.assertEqual(escape_query("abcd&"), "abcd") self.assertEqual(escape_query("abcd&&&"), "abcd") self.assertEqual(escape_query("abcd|efgh"), "abcd&efgh") self.assertEqual(escape_query("abcd!efgh"), "abcd&efgh") self.assertEqual(escape_query("abcd:efgh"), "abcd&efgh") self.assertEqual(escape_query("abcd(efgh"), "abcd&efgh") self.assertEqual(escape_query("abcd)efgh"), "abcd&efgh")