Skip to content

Commit

Permalink
Remove extra whitespace when parsing search inputs. (#8466)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 16, 2025
1 parent 127f6fc commit f43044b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AppEngine version, listed here to ease deployment and troubleshooting.
## Next Release (replace with git tag when deployed)
* Bump runtimeVersion to `2025.01.15`.
* Note: started deleting `Package.isBlocked`, `Publisher.isBlocked`, `User.isBlocked`.
* Note: Updates search form normalization: whitespaces.

## `20250114t095800-all`
* Bump runtimeVersion to `2025.01.14`.
Expand Down
2 changes: 1 addition & 1 deletion pkg/_pub_shared/lib/search/search_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class SearchForm {
}) {
currentPage ??= 1;
pageSize ??= resultsPerPage;
final q = _stringToNull(query?.trim());
final q = _stringToNull(query?.replaceAll(_whitespacesRegExp, ' ').trim());
return SearchForm._(
query: q,
order: order,
Expand Down
5 changes: 5 additions & 0 deletions pkg/_pub_shared/test/search/search_form_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ void main() {
expect(form.toSearchLink(page: 3), '/packages?q=web+framework&page=3');
});

test('query with extra whitespaces', () {
final form = SearchForm(query: ' aa bbb cc ');
expect(form.query, 'aa bbb cc');
});

test('query with sdk context', () {
final form = SearchForm(query: 'sdk:flutter some framework');
expect(form.toSearchLink(), '/packages?q=sdk%3Aflutter+some+framework');
Expand Down

0 comments on commit f43044b

Please sign in to comment.