Skip to content

Commit f43044b

Browse files
authored
Remove extra whitespace when parsing search inputs. (#8466)
1 parent 127f6fc commit f43044b

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ AppEngine version, listed here to ease deployment and troubleshooting.
44
## Next Release (replace with git tag when deployed)
55
* Bump runtimeVersion to `2025.01.15`.
66
* Note: started deleting `Package.isBlocked`, `Publisher.isBlocked`, `User.isBlocked`.
7+
* Note: Updates search form normalization: whitespaces.
78

89
## `20250114t095800-all`
910
* Bump runtimeVersion to `2025.01.14`.

pkg/_pub_shared/lib/search/search_form.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class SearchForm {
367367
}) {
368368
currentPage ??= 1;
369369
pageSize ??= resultsPerPage;
370-
final q = _stringToNull(query?.trim());
370+
final q = _stringToNull(query?.replaceAll(_whitespacesRegExp, ' ').trim());
371371
return SearchForm._(
372372
query: q,
373373
order: order,

pkg/_pub_shared/test/search/search_form_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ void main() {
3030
expect(form.toSearchLink(page: 3), '/packages?q=web+framework&page=3');
3131
});
3232

33+
test('query with extra whitespaces', () {
34+
final form = SearchForm(query: ' aa bbb cc ');
35+
expect(form.query, 'aa bbb cc');
36+
});
37+
3338
test('query with sdk context', () {
3439
final form = SearchForm(query: 'sdk:flutter some framework');
3540
expect(form.toSearchLink(), '/packages?q=sdk%3Aflutter+some+framework');

0 commit comments

Comments
 (0)