Exemple #1
0
    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")
Exemple #2
0
    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"
            )
Exemple #3
0
 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()
     )
Exemple #4
0
 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")