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

Add a test for truncate when length is NaN #499

Closed
SeanPrashad opened this issue Sep 24, 2018 · 2 comments

Comments

Projects
None yet
1 participant
@SeanPrashad
Copy link
Contributor

commented Sep 24, 2018

Let's consider adding a test for when fs.truncate's length parameter is NaN (ie. Not a number like stringInputForTruncateExplodes).

The tests live within filer/tests/spec/fs.truncate.spec.js and could possibly slide right under the test when length is negative!

Node.js docs

@SeanPrashad

This comment has been minimized.

Copy link
Contributor Author

commented Sep 24, 2018

I'll see this one through to finish - keep your 👀 open for a PR!

@SeanPrashad

This comment has been minimized.

Copy link
Contributor Author

commented Sep 24, 2018

Update: Very interesting - there is no error when a string is passed in for the length, meaning that there's a default somewhere. Currently looking for Found it!

Test Output:

screen shot 2018-09-24 at 5 54 43 pm


The implementation can be found starting at:

function truncate_file(context, path, length, callback) {

Update 2: It looks like the length is only checked if it's length is less than 0, let's add a check to see if it's a valid number before we check if it's less than 0 using Number.IsInteger():

if(length < 0) {
callback(new Errors.EINVAL('length cannot be negative'));
} else {
find_node(context, path, read_file_data);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.