Skip to content

Commit

Permalink
Strip forbidden characters from the end of search term to avoid synta…
Browse files Browse the repository at this point in the history
…x errors (#141)

* Strip forbidden characters from the end of search term to avoid syntax errors

* Revert syntax tweaking

* Simplify logic
  • Loading branch information
HPiirainen authored Aug 19, 2024
1 parent 0d13d78 commit cc7e7a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [2.0.10] - 2024-08-16

### Fixed
- Strip forbidden characters from the end of search term to avoid syntax errors.

## [2.0.9] - 2024-01-18

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: RediPress
* Plugin URI: https://github.com/devgeniem/redipress
* Description: A WordPress plugin that provides a blazing fast search engine and WP Query performance enhancements.
* Version: 2.0.9
* Version: 2.0.10
* Author: Geniem
* Author URI: http://www.geniem.fi/
* License: GPL3
Expand Down
8 changes: 8 additions & 0 deletions src/Search/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ protected function conduct_search( string $parameter ) : string {
$terms = apply_filters( 'redipress/search_terms/raw', $terms );
$terms = apply_filters( 'redipress/search_terms/raw/' . static::TYPE, $terms );

// Remove a list of forbidden characters if they appear as the very last character ignoring trailing whitespace.
$terms = rtrim( $terms );
$forbidden_last_characters = str_split( '*/`' );

while ( in_array( substr( $terms, -1 ), $forbidden_last_characters, true ) ) {
$terms = substr( $terms, 0, -1 );
}

// Remove a list of forbidden characters based on RediSearch restrictions.
$forbidden_characters = str_split( ',.<>{}[]"\':;!?@#$%^&()+=~' );

Expand Down

0 comments on commit cc7e7a5

Please sign in to comment.