Skip to content

Commit

Permalink
case-insensitive package filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
nl0 committed Sep 18, 2020
1 parent 2b04b62 commit 694661d
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions catalog/app/containers/Bucket/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as R from 'ramda'
import { SUPPORTED_EXTENSIONS as IMG_EXTS } from 'components/Thumbnail'
import { mkSearch } from 'utils/NamedRoutes'
import * as Resource from 'utils/Resource'
import pipeThru from 'utils/pipeThru'
import * as s3paths from 'utils/s3paths'
import tagged from 'utils/tagged'

Expand Down Expand Up @@ -609,12 +610,33 @@ const fetchPackagesAccessCounts = async ({
}
}

// eslint-disable-next-line no-underscore-dangle
const isReserved = R.includes(R.__, '.+|{}[]()"\\')

const escapeReserved = (c) => `\\${c}`

const isLetter = (c) => c.toLowerCase() !== c.toUpperCase()

const bothCases = (c) => `(${c.toLowerCase()}|${c.toUpperCase()})`

const mkFilterQuery = (filter) =>
filter
? {
wildcard: {
regexp: {
handle: {
value: filter.includes('*') ? filter : `*${filter}*`,
value: pipeThru(filter)(
R.unless(R.test(/[*?]/), (f) => `*${f}*`),
R.map(
R.cond([
[isLetter, bothCases],
[isReserved, escapeReserved],
[R.equals('*'), () => '.*'],
[R.equals('?'), () => '.{0,1}'],
[R.T, R.identity],
]),
),
R.join(''),
),
},
},
}
Expand Down

0 comments on commit 694661d

Please sign in to comment.