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

FileSink constructor should guard against empty/whitespace paths #287

Closed
reubenalfred opened this issue Jun 12, 2023 · 8 comments
Closed

Comments

@reubenalfred
Copy link

Hi,

I was just browsing the FileSink file and noticed that the path parameter is only tested for null and doesn't include a test for NullOrWhiteSpace.

Further down in the constructor, it is tested to see if the path's dir is null or white space and creates the directory if the path string is valid, however, no action is specified when the string is empty.

it is an internal constructor, perhaps it may not be that important. i thought i'd let you know...

regards, reuben

filesink

@reubenalfred
Copy link
Author

if it needs fixing ill be happy to do that :)

@nblumhardt
Copy link
Member

Hi @reubenalfred! string.IsNullOrWhiteSpace("") is true so I don't think the empty string case is neglected here.

@Micke3rd
Copy link

Micke3rd commented Jun 25, 2023

action is specified when the string is empty

string.IsNullOrWhiteSpace:
"true if the value parameter is null or Empty, or if value consists exclusively of white-space characters."
doc

@reubenalfred
Copy link
Author

reubenalfred commented Jun 25, 2023

If it is null or white space it won't create the directory sure but it will still attempt to execute the rest of the code without a definite directory.

path too should be tested for null or white space at the top instead of just testing for null alone.

@reubenalfred
Copy link
Author

action is specified when the string is empty

string.IsNullOrWhiteSpace: "true if the value parameter is null or Empty, or if value consists exclusively of white-space characters." doc

Where is the action specified? Please show me??

@Micke3rd
Copy link

Micke3rd commented Jun 26, 2023

If it is null or white space it won't create the directory sure but it will still attempt to execute the rest of the code without a definite directory.

ah got it. Yes, I thought you mean the create directory part.

path too should be tested for null or white space at the top instead of just testing for null alone.

Yes, would be an improvement.
System.IO.File.Open itself contains a ThrowIfNullOrEmpty(path), which you would probably copy to the top line.
It would therefore be redundant, but also not because the check at CreateDirectory can then be omitted.

if it needs fixing ill be happy to do that :)

do it ... I would be surprised if the team here turns down the help.

@reubenalfred
Copy link
Author

Cool will do that, I personally like to test for obvious and explicitly throw exceptions rather than rely on the API's otherwise it is too much to remember what throws what!

@bartelink
Copy link
Member

@reubenalfred I'm spring cleaning (e.g. #297 (comment) #263 (comment))

Before any work takes place to add checks, it'd be good for us to collectively get #258 over the line, as it may already be address some of these issues.

In short, as:

  • we want/need all null checks to be complete and correct
  • if there is an issue that clearly and concisely documents a desired behavior change wrt empty strings in some cases, then a PR can make the requisite changes
  • in general whitespace trimming is not something that we want to do

The next steps here are to make sure your concerns are covered by either
a) commenting on #258
b) writing a new issue detailing the needs (no large screeshots please though ;))

@bartelink bartelink closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2023
@bartelink bartelink changed the title FileSink constructor checking only path for null FileSink constructor should gard against empty/whitespace paths Oct 25, 2023
@bartelink bartelink changed the title FileSink constructor should gard against empty/whitespace paths FileSink constructor should guard against empty/whitespace paths Oct 25, 2023
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

No branches or pull requests

4 participants