Skip to content

Commit

Permalink
PER-9353
Browse files Browse the repository at this point in the history
Some small changes to the new function body.
  • Loading branch information
crisnicandrei committed Oct 24, 2023
1 parent 2a474a9 commit f782698
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
28 changes: 18 additions & 10 deletions src/app/search/services/search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,7 @@ describe('SearchService', () => {
);
});

function expectSearchToBe(
search: [string, TagVOData[]],
expectedSearch: string,
expectedTags: TagVOData[]
) {
expect(search[0]).toBe(expectedSearch);
expect(search[1]).toEqual(expectedTags);
}

it('removes the first and last quotation marks from tag names', () => {
it('handles quotation marks in tag names properly', () => {
tags.setTags([
{ name: 'Potato', tagId: 0 },
{ name: '"Potato"', tagId: 1 },
Expand Down Expand Up @@ -232,4 +223,21 @@ describe('SearchService', () => {
service.getResultsInPublicArchive('Test', [], '1');
expect(apiSpy).toHaveBeenCalled();
});

it('cannot handle tags with quotation marks followed by search terms with quotation marks', () => {
tags.setTags([{ name: '"A Multiword Tag"', tagId: 0 }]);
const searchTokens = service.parseSearchTerm(
'tag:""A Multiword Tag"" "potato"'
);
expect(searchTokens[1].length).toBe(0);
});

function expectSearchToBe(
search: [string, TagVOData[]],
expectedSearch: string,
expectedTags: TagVOData[]
) {
expect(search[0]).toBe(expectedSearch);
expect(search[1]).toEqual(expectedTags);
}
});
10 changes: 2 additions & 8 deletions src/app/search/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,8 @@ export class SearchService {
return [queryString, parsedTags];
}

private removeFirstAndLastQuotes(str) {
if (str.startsWith('"')) {
str = str.substr(1);
}
if (str.endsWith('"')) {
str = str.substring(0, str.length - 1);
}
return str;
private removeFirstAndLastQuotes(str: string): string {
return str.replace(/^"|"$/g, '');
}

public getResultsInCurrentArchive(
Expand Down

0 comments on commit f782698

Please sign in to comment.