Skip to content

Commit

Permalink
change: [UIE-8440] - Allow more symbols to be used in Search v2 (#11616)
Browse files Browse the repository at this point in the history
Co-authored-by: Banks Nussman <[email protected]>
  • Loading branch information
bnussman-akamai and bnussman authored Feb 6, 2025
1 parent bd79814 commit 33143b1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/search/src/search.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ String "search value"
/ Word

Word "word"
= [a-zA-Z0-9\-\.]+ { return text(); }
= [a-zA-Z0-9-_.@]+ { return text(); }

StringWithSpaces "string with spaces"
= [a-zA-Z0-9\-|_\.\: ]+ { return text(); }
= [a-zA-Z0-9-_.:@ ]+ { return text(); }

Number "numeric search value"
= number:[0-9\.]+ { return parseFloat(number.join("")); }
Expand Down
33 changes: 33 additions & 0 deletions packages/search/src/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,39 @@ describe("getAPIFilterFromQuery", () => {
});
});

it("allows '@' symbol in search", () => {
const query = 'email: [email protected]';

expect(getAPIFilterFromQuery(query, { searchableFieldsWithoutOperator: [] })).toEqual({
filter: {
email: { '+contains': "[email protected]" }
},
error: null,
});
});

it("allows '-' symbol in search", () => {
const query = 'username: test-user-1';

expect(getAPIFilterFromQuery(query, { searchableFieldsWithoutOperator: [] })).toEqual({
filter: {
username: { '+contains': "test-user-1" }
},
error: null,
});
});

it("allows '_' symbol in search", () => {
const query = 'username: test_user_1';

expect(getAPIFilterFromQuery(query, { searchableFieldsWithoutOperator: [] })).toEqual({
filter: {
username: { '+contains': "test_user_1" }
},
error: null,
});
});

it("allows a quoted string so you can use spaces in the query (single quotes)", () => {
const query = "label: 'my stackscript' and username = linode";

Expand Down

0 comments on commit 33143b1

Please sign in to comment.