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
[Image Uploader] fix naming convention check #2100
Conversation
if (($file_name != $pscid."_". $candid ."_". $visit_label . ".zip") | ||
&& ($file_name != $pscid."_". $candid ."_". $visit_label . ".tgz") | ||
&& ($file_name != $pscid."_". $candid ."_". $visit_label . ".tar.gz") | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
/**
* Checks if the inputted file name is valid
*
* @param {string} requiredFileName - Required file name
* @param {string} fileName - Provided file name
* @return {boolean} - true if file names match and false otherwise
*/
isValidFileName: function(requiredFileName, fileName) {
if (fileName === null || requiredFileName === null) {
return false;
}
return (fileName.indexOf(requiredFileName) > -1);
}
Note: snippet is in JS, but can be adapted to PHP easily using strpos()
Note 2: If you want requiredFileName to always be the beginning of the fileName, use:
return (fileName.indexOf(requiredFileName) === 0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively you could use a regular expression. Something likelike:
if preg_match(/^{$pscid}{$candid}{$visit_label}.*(zip|tgz|tar.gz/) {
}
789fae4
to
b8add23
Compare
Current coverage is 13.71% (diff: 0.00%)@@ 16.1-dev #2100 diff @@
==========================================
Files 118 118
Lines 19923 20065 +142
Methods 1116 1116
Messages 0 0
Branches 0 0
==========================================
+ Hits 2678 2752 +74
- Misses 17245 17313 +68
Partials 0 0
|
Update documentation to tell people what filenames the imaging uploader will accept:
|
* fix naming convention * length of $candid & $visit_label can vary, looking for the whole string at once * rephrase the error message
Previous name was too strict.