Skip to content

Commit

Permalink
fix(regex): ensure that integer query param can be sent and converted…
Browse files Browse the repository at this point in the history
… to regex safe

close #451
  • Loading branch information
PauloGoncalvesBH committed Jan 25, 2024
1 parent 4e81871 commit b565d88
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/utils/alterarValoresParaRegex.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ module.exports = queryString => {
delete queryString[key]
} else if (permittedKeys.includes(key)) {
try {
// Ensure queryString[key] is a string
const queryStringValue = typeof queryString[key] === 'string' ? queryString[key] : String(queryString[key])
// Add 'i' flag for case-insensitive matching
queryString[key] = new RegExp(escapeStringRegexp(queryString[key]), 'i')
queryString[key] = new RegExp(escapeStringRegexp(queryStringValue), 'i')
} catch (error) /* istanbul ignore next */ {
log({ level: 'error', message: `Failed to convert ${key} to RegExp: ${error.message}` })
throw error
Expand Down
2 changes: 1 addition & 1 deletion test/unit/alterarValoresParaRegex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('alterarValoresParaRegex', () => {
it('should convert specified fields to RegExp', () => {
const queryString = {
nome: 'test',
password: '1234',
password: 1234,
descricao: 'description',
other: 'field'
}
Expand Down

0 comments on commit b565d88

Please sign in to comment.