Skip to content

Commit

Permalink
Bugfix: Allow regex validation not to be evaluated when all values ar…
Browse files Browse the repository at this point in the history
…e empty if required
  • Loading branch information
alejandro-bulgaris-qcif committed Mar 7, 2025
1 parent 73f23f5 commit cc2e67a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions typescript/api/services/FigshareService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,10 @@ export module Services {

} catch (error) {
sails.log.error(error);
if(!_.isEmpty(_.get(error,'response.data.message',''))) {
let customError: RBValidationError = new RBValidationError(_.get(error,'response.data.message'));
throw customError;
}
throw error;
}

Expand Down Expand Up @@ -1181,15 +1185,20 @@ export module Services {
} else if(regexValidation != ''){
let val = _.get(requestBody,field.figName,'');
let caseSensitive = _.get(validation,'caseSensitive',true);
if(caseSensitive) {
let re = new RegExp(regexValidation);
if(!re.test(val)) {
valid = TranslationService.t(_.get(validation,'message','Error on request to Figshare'));
}
let skipIfEmpty = _.get(validation,'skipIfEmpty',false);
if(skipIfEmpty && _.trim(val) == '') {
//do nothing
} else {
let re = new RegExp(regexValidation,'i');
if(!re.test(val)) {
valid = TranslationService.t(_.get(validation,'message','Error on request to Figshare'));
if(caseSensitive) {
let re = new RegExp(regexValidation);
if(!re.test(val)) {
valid = TranslationService.t(_.get(validation,'message','Error on request to Figshare'));
}
} else {
let re = new RegExp(regexValidation,'i');
if(!re.test(val)) {
valid = TranslationService.t(_.get(validation,'message','Error on request to Figshare'));
}
}
}
}
Expand Down

0 comments on commit cc2e67a

Please sign in to comment.