File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
WooCommerce/Classes/ViewRelated/Search Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -84,13 +84,24 @@ protocol SearchUICommand {
8484
8585 /// The Accessibility Identifier for the cancel button
8686 var cancelButtonAccessibilityIdentifier : String { get }
87+
88+ /// Optionally sanitizes the search keyword.
89+ ///
90+ /// - Parameter keyword: user-entered search keyword.
91+ /// - Returns: sanitized search keyword.
92+ func sanitizeKeyword( _ keyword: String ) -> String
8793}
8894
8995// MARK: - Default implementation
9096extension SearchUICommand {
9197 func configureActionButton( _ button: UIButton , onDismiss: @escaping ( ) -> Void ) {
9298 // If not implemented, keeps the default cancel UI/UX
9399 }
100+
101+ func sanitizeKeyword( _ keyword: String ) -> String {
102+ // If not implemented, returns the keyword as entered
103+ return keyword
104+ }
94105}
95106
96107// MARK: - SearchUICommand using EmptySearchResultsViewController
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ where Cell.SearchModel == Command.CellViewModel {
7070 /// Returns the active Keyword
7171 ///
7272 private var keyword : String {
73- return searchBar. text ?? String ( )
73+ return searchUICommand . sanitizeKeyword ( searchBar. text ?? String ( ) )
7474 }
7575
7676 /// UI Active State
@@ -205,7 +205,8 @@ where Cell.SearchModel == Command.CellViewModel {
205205 // MARK: - UISearchBarDelegate Conformance
206206 //
207207 func searchBar( _ searchBar: UISearchBar , textDidChange searchText: String ) {
208- synchronizeSearchResults ( with: searchText)
208+ let sanitizedSearchText = searchUICommand. sanitizeKeyword ( searchText)
209+ synchronizeSearchResults ( with: sanitizedSearchText)
209210 }
210211
211212 func searchBarShouldBeginEditing( _ searchBar: UISearchBar ) -> Bool {
You can’t perform that action at this time.
0 commit comments