ElasticPress
ElasticPress copied to clipboard
BUG: Wrong separator used in get_synonyms on Windows
Describe the bug
The Synonym feature doesn't work when hosted on Windows.
In wp-content\plugins\elasticpress\includes\classes\Feature\Search\Synonyms.php we can se that the synonyms are separated (explode) by PHP_EOL, which is \r\n on Windows:
public function get_synonyms() {
$synonyms_raw = $this->get_synonyms_raw();
$synonyms = array_values(
array_filter(
array_map( [ $this, 'validate_synonym' ], explode( PHP_EOL, $synonyms_raw ) )
)
);
/**
* Filter array of synonyms to add to a custom synonym filter.
*
* @hook ep_synonyms
* @return {array} The new array of search synonyms.
*/
return apply_filters( 'ep_synonyms', $synonyms );
}
But it looks like $this->get_synonyms_raw() always returns a string with synonyms separated by \n. On Linux, PHP_EOL is defined as \n, so this issue does not appear when running on that OS.
Changing PHP_EOL to "\n" resolves the issue on Windows.
Steps to Reproduce
- Host on a Windows environment
- Add synonyms
- Try to use those synonyms
Screenshots, screen recording, code snippet
No response
Environment information
No response
WordPress and ElasticPress information
No response
Code of Conduct
- [x] I agree to follow this project's Code of Conduct