Skip to content

File name pattern regex filter not working #2823

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

Closed
ANTGOMEZ opened this issue Dec 13, 2021 · 4 comments
Closed

File name pattern regex filter not working #2823

ANTGOMEZ opened this issue Dec 13, 2021 · 4 comments

Comments

@ANTGOMEZ
Copy link

ANTGOMEZ commented Dec 13, 2021

I have a file parameter on which I want to apply a regex pattern so that only file names with a certain set of chars is allowed.

For example, I only want file names like this to be allowed through:

filename.csv
fileName.csv
FileName.csv
FILENAME.CSV
file-name.csv
file_name.csv
file-name123.csv
file_name123.csv

In other words, I want file name to have ONLY: alphanumeric with dash, underscore and dot, mixed cases, (NO SPACES)

The following pattern allows everything, even file names with spaces and should not.

parameters:
- name: file
  type: file
  in: formData
  description: Select the Catalog file to upload
  required: true
  format: file
  pattern: '[\w._-]+'

The following pattern doesn't allow anything through...

parameters:
- name: file
  type: file
  in: formData
  description: Select the Catalog file to upload
  required: true
  format: file
  pattern: '^[a-zA-Z0-9._-]+$'

Looked through Docs and saw nothing helpful for this.

Am I missing something?

Thanks!

@du-it
Copy link

du-it commented Dec 19, 2021

Are digits allowed only at the end of the filename or at any place?
The dot may scour anywhere or only just before the suffix?
The suffix may have any length?
An example for filenames allowing your specified characters with digits at any place and a suffix of any length. Only the '.' just preceding the suffix is allowed:
^[a-zA-Z0-9_-]+.[a-zA-Z0-9_-]+$

@karenetheridge
Copy link
Member

pattern is a json schema keyword, and therefore needs to be under the schema property in your specification.

@hkosova
Copy link
Contributor

hkosova commented Dec 20, 2021

@karenetheridge this is OpenAPI 2.0, where non-body parameters don't use schema.

@hkosova
Copy link
Contributor

hkosova commented Dec 20, 2021

@ANTGOMEZ the pattern applies to the parameter value, which is this case is the file contents, not its name. The specification currently has no way to limit the file names for file uploads.

Related: #2458.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants