Provides a mechanism for sanitizing user input before presenting the value to the backend. A basic (override-able) implementation is provided.
(self, query_fragment)
| 766 | # Standard methods to alter the query. |
| 767 | |
| 768 | def clean(self, query_fragment): |
| 769 | """ |
| 770 | Provides a mechanism for sanitizing user input before presenting the |
| 771 | value to the backend. |
| 772 | |
| 773 | A basic (override-able) implementation is provided. |
| 774 | """ |
| 775 | if not isinstance(query_fragment, str): |
| 776 | return query_fragment |
| 777 | |
| 778 | words = query_fragment.split() |
| 779 | cleaned_words = [] |
| 780 | |
| 781 | for word in words: |
| 782 | if word in self.backend.RESERVED_WORDS: |
| 783 | word = word.replace(word, word.lower()) |
| 784 | |
| 785 | for char in self.backend.RESERVED_CHARACTERS: |
| 786 | word = word.replace(char, "\\%s" % char) |
| 787 | |
| 788 | cleaned_words.append(word) |
| 789 | |
| 790 | return " ".join(cleaned_words) |
| 791 | |
| 792 | def build_not_query(self, query_string): |
| 793 | if " " in query_string: |
no outgoing calls
no test coverage detected