Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case-insensitive package filtering #1807

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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