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

Dont allow blank patch names or categories #326

Merged
merged 1 commit into from
Jan 18, 2019

Conversation

baconpaul
Copy link
Collaborator

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!

std::string whatIsBlank = "";
bool haveBlanks = false;

if (std::string(patchName->getText()).find_first_not_of( ' ' ) == std::string::npos)
Copy link
Collaborator

@jarkkojs jarkkojs Jan 17, 2019

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.

Copy link
Collaborator

@jarkkojs jarkkojs Jan 17, 2019

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;
}

}

}

Copy link
Collaborator

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.

Copy link
Collaborator Author

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

}
if (haveBlanks)
{
Surge::UserInteractions::promptError(std::string("Unable to store a patch with a blank ") +
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

{
whatIsBlank = "name"; haveBlanks = true;
}
if (std::string(patchCategory->getText()).find_first_not_of( ' ' ) == std::string::npos)
Copy link
Collaborator

@jarkkojs jarkkojs Jan 17, 2019

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.

Copy link
Collaborator Author

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!

@baconpaul
Copy link
Collaborator Author

Thanks as always @jsakkine - good comments. I’ll fix em and merge over the weekend

@jarkkojs
Copy link
Collaborator

@baconpaul, glad to help :)

@baconpaul
Copy link
Collaborator Author

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

  1. Put this namespace at the bottom of SurgeStorage.h
    • pros - it is code all in the same place
    • cons - it is just a namespace at the end
  2. Put this namespace in a new header
    • pros - namespace stuff is distinct
    • cons - functions on storage are spread all around
  3. Don't namespace this and make it a member of SurgeStorage
    • pros - the most like current code
    • cons - that's probably not true in the future and the future starts today

Your opinion welcome. I'm going to do 1 now but not force it until I hear from you

@jarkkojs
Copy link
Collaborator

jarkkojs commented Jan 18, 2019

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.

@baconpaul
Copy link
Collaborator Author

Ha ha! IsValidThingWhichWeCanUseAsAStringForManyPurposesInSurge

I will do IsValidStorageName

I won't move the SurgeStorage class in this PR, but agree we should do it shortly.

@jarkkojs
Copy link
Collaborator

Why not just isValidName()? It is anyway in Storage namespace.

@baconpaul
Copy link
Collaborator Author

Yeah OK. It feels weird but not enough that I can push back so I'll pick that!

@baconpaul baconpaul force-pushed the idontwantnoblanks-282 branch from a6c3426 to a560803 Compare January 18, 2019 02:22
@baconpaul
Copy link
Collaborator Author

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
@baconpaul baconpaul force-pushed the idontwantnoblanks-282 branch from a6e34f9 to 7a8a8be Compare January 18, 2019 02:43
@baconpaul baconpaul merged commit 646c525 into surge-synthesizer:master Jan 18, 2019
@baconpaul baconpaul deleted the idontwantnoblanks-282 branch January 18, 2019 22:23
baconpaul added a commit to baconpaul/surge that referenced this pull request Jul 10, 2019
…anks-282

Dont allow blank patch names or categories

Former-commit-id: 0725600696b07a7b8469e8d0ce57eb37d32c484c [formerly 646c525]
Former-commit-id: 0055d8f3b0f40bbdf7e5bd49b8f69896a2da2cd7
Former-commit-id: 5dcb102110dce1ee961ae8c7a03115272c98348f
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.

2 participants