-
Notifications
You must be signed in to change notification settings - Fork 404
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
Dont allow blank patch names or categories #326
Dont allow blank patch names or categories #326
Conversation
src/common/gui/SurgeGUIEditor.cpp
Outdated
std::string whatIsBlank = ""; | ||
bool haveBlanks = false; | ||
|
||
if (std::string(patchName->getText()).find_first_not_of( ' ' ) == std::string::npos) |
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.
What about a tab character or something even weirder (from the ASCII range)? I think you should validate that for a patch
- The only allowed non-displayable character is a space bar.
- Must have at least one displayable character.
- Is at least one character length.
I think these are fair assumptions for a patch name.
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.
e.g.
namespace Surge
{
namespace Utility
{
bool validatePatchName(const std::string& patchName)
{
bool visible = false;
// No need to validate size separately as an empty string won't have visible characters.
for (const char &c : patchName)
if (std::isalnum(c) || std::ispunct(c))
visible = true;
else if (c != ' ')
return false;
return visible;
}
}
}
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.
I think doing this C-style instead of string class magic functions documents actually best how a patch name is validated and probably performs best too.
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.
Yeah that’s a better idea. I will adjust thusly
src/common/gui/SurgeGUIEditor.cpp
Outdated
} | ||
if (haveBlanks) | ||
{ | ||
Surge::UserInteractions::promptError(std::string("Unable to store a patch with a blank ") + |
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.
Personal preference is std::string() +
but not big issue for me.
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.
Agree Never use it in a loop. For a one off concat it you don’t get the n^2 problem which ostringstream obviates so I think it is fine here.
src/common/gui/SurgeGUIEditor.cpp
Outdated
{ | ||
whatIsBlank = "name"; haveBlanks = true; | ||
} | ||
if (std::string(patchCategory->getText()).find_first_not_of( ' ' ) == std::string::npos) |
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.
validatePatchName()
could be called in both of these call sites.
I would also use it when we scanning all the patches in SurgeStorage, but that is up to you. I would just skip the patches that have invalid filenames, possibly giving one promptError() after the scan that reports the number of patches that were skipped because of this reason. Allowing to load such patches brings it own set of corner cases to the plugins run-time state, as you can probably understand.
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.
Right let me add the function here and call it so we can reuse it but not reuse it yet. This is really a ui thing for not saving bad ones
On and the reason I only checked space is the ui doesn’t let you make a tab. But the is alpha church is way better. Thanks as always!
Thanks as always @jsakkine - good comments. I’ll fix em and merge over the weekend |
@baconpaul, glad to help :) |
So @jsakkine I really I want to make a function with name Surge::Storage::isValidPatchOrCategoryName since SurgeStorage is the representation of a patch used in all parts of the codebase. So do I
Your opinion welcome. I'm going to do 1 now but not force it until I hear from you |
I would name the function as isValidEntityName() and put it to Surge::Storage namespace. I would also move the class to that namespace and rename it as Storage. Since the function is in Storage namespace, it is obvious what is meant by entity. The naming that you propose would ignore wavetables. It should be isValidPatchOrPatchCategoryOrWavetableOrWavetableCategoryName() to be exact :) Becomes a largeish change, since also Patch and PatchCategory move to that name space, but I think it is good idea do things right at once. |
Ha ha! IsValidThingWhichWeCanUseAsAStringForManyPurposesInSurge I will do IsValidStorageName I won't move the SurgeStorage class in this PR, but agree we should do it shortly. |
Why not just isValidName()? It is anyway in Storage namespace. |
Yeah OK. It feels weird but not enough that I can push back so I'll pick that! |
a6c3426
to
a560803
Compare
Thank you automated builds! Checking windows now. |
Prompt a user error in this case rather than making blank named files Incorporate review feedback from @jsakkine
a6e34f9
to
7a8a8be
Compare
…anks-282 Dont allow blank patch names or categories Former-commit-id: 0725600696b07a7b8469e8d0ce57eb37d32c484c [formerly 646c525] Former-commit-id: 0055d8f3b0f40bbdf7e5bd49b8f69896a2da2cd7 Former-commit-id: 5dcb102110dce1ee961ae8c7a03115272c98348f
Prompt a user error in this case rather than making blank named files
Fixes the error reported in #282 by not allowing the user to enter that
code path.
Eyeball or test appreciated. Thanks!