Skip to content

Commit

Permalink
refactor: collection search query (#3908)
Browse files Browse the repository at this point in the history
  • Loading branch information
balub committed Mar 19, 2024
1 parent 66f20d1 commit a3f3e3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
Expand Up @@ -13,15 +13,15 @@ import { throwHTTPErr } from 'src/utils';
export class TeamCollectionController {
constructor(private readonly teamCollectionService: TeamCollectionService) {}

@Get('search/:teamID/:searchQuery')
@Get('search/:teamID')
@RequiresTeamRole(
TeamMemberRole.VIEWER,
TeamMemberRole.EDITOR,
TeamMemberRole.OWNER,
)
@UseGuards(JwtAuthGuard, RESTTeamMemberGuard)
async searchByTitle(
@Param('searchQuery') searchQuery: string,
@Query('searchQuery') searchQuery: string,
@Param('teamID') teamID: string,
@Query('take') take: string,
@Query('skip') skip: string,
Expand Down
47 changes: 23 additions & 24 deletions packages/hoppscotch-backend/src/utils.ts
Expand Up @@ -261,29 +261,28 @@ export function checkEnvironmentAuthProvider(
* Source: https://stackoverflow.com/a/32648526
*/
export function escapeSqlLikeString(str: string) {
if (typeof str != 'string')
return str;
if (typeof str != 'string') return str;

return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
switch (char) {
case "\0":
return "\\0";
case "\x08":
return "\\b";
case "\x09":
return "\\t";
case "\x1a":
return "\\z";
case "\n":
return "\\n";
case "\r":
return "\\r";
case "\"":
case "'":
case "\\":
case "%":
return "\\"+char; // prepends a backslash to backslash, percent,
// and double/single quotes
}
});
return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
switch (char) {
case '\0':
return '\\0';
case '\x08':
return '\\b';
case '\x09':
return '\\t';
case '\x1a':
return '\\z';
case '\n':
return '\\n';
case '\r':
return '\\r';
case '"':
case "'":
case '\\':
case '%':
return '\\' + char; // prepends a backslash to backslash, percent,
// and double/single quotes
}
});
}

0 comments on commit a3f3e3e

Please sign in to comment.