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

Fix regular expressions #1070

Merged
merged 1 commit into from
Sep 28, 2023
Merged

Fix regular expressions #1070

merged 1 commit into from
Sep 28, 2023

Conversation

axelboc
Copy link
Collaborator

@axelboc axelboc commented Sep 28, 2023

Seems that the regexes modified by ESLint in https://github.com/mxcube/mxcubeweb/pull/1068/files#diff-f10f5ea4f3870e6bbd1c60836649382147f2438b75b4b7eb505f9e8bfed69fd8 were no longer valid.

This tool can help understand the old/new regexes: https://regex101.com/

@@ -24,15 +24,15 @@ const validate = (values, props) => {
// here we update the resolution limits based on the energy the typed in the form,
// the limits come from a table sent by the client

const validFname = /^[\w#[\]{}-\-]+$/u.test(props.filename);
const validFname = /^[-_#{}[\]\w]+$/u.test(props.filename);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial regex was /^[-\w\-\#\_\{\}\[\]]+$/.

  • None of the characters need to be escaped except ].
  • The dash was provided unescaped and escaped. I've kept the unescaped one and kept it at the start of the character set (i.e. [...]) so it is never considered as a range (e.g. a-z).


const emptyField = 'field is empty';

if (!validFname) {
errors.prefix = INVALID_CHAR_MSG;
}

if (props.subdir && !/^[\w/{}-\-]+$/u.test(props.subdir)) {
if (props.subdir && !/^[-{}\/\w]+$/u.test(props.subdir)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial regex was /^[-\w\-\/\_\{\}]+$/. Same problem with the dash: it has to be at the front and doesn't need to be specified twice.

@marcus-oscarsson marcus-oscarsson merged commit 9d05de2 into develop Sep 28, 2023
10 of 11 checks passed
@marcus-oscarsson marcus-oscarsson deleted the ab-fix-regex branch September 28, 2023 13:52
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

Successfully merging this pull request may close these issues.

3 participants