8000 Remove trailing spaces from search query by apoorv-mishra · Pull Request #7314 · outline/outline · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove trailing spaces from search query #7314

8000 New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions server/models/helpers/SearchHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,25 @@ describe("SearchHelper", () => {
);
expect(totalCount).toBe(1);
});

test("should correctly handle removal of trailing spaces", async () => {
const team = await buildTeam();
const user = await buildUser({ teamId: team.id });
const collection = await buildCollection({
teamId: team.id,
userId: user.id,
});
const document = await buildDocument({
teamId: team.id,
userId: user.id,
collectionId: collection.id,
text: "env: some env",
});
document.title = "change";
await document.save();
const { totalCount } = await SearchHelper.searchForUser(user, "env: ");
expect(totalCount).toBe(1);
});
});

describe("#searchTitlesForUser", () => {
Expand Down
7 changes: 6 additions & 1 deletion server/models/helpers/SearchHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,12 @@ export default class SearchHelper {
}

return (
queryParser()(quotedSearch ? limitedQuery : `${limitedQuery}*`)
queryParser()(
// Although queryParser trims the query, looks like there's a
// bug for certain cases where it removes other characters in addition to
// spaces. Ref: https://github.com/caub/pg-tsquery/issues/27
quotedSearch ? limitedQuery.trim() : `${limitedQuery.trim()}*`
)
// Remove any trailing join characters
.replace(/&$/, "")
);
Expand Down
Loading
0