Trim text for key list filtering
(cherry picked from commit 5780ab222eec9eef6a456eba211f9d3274939748)