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

test: check zlib version for createDeflateRaw #13697

Closed
wants to merge 6 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions test/parallel/test-zlib-failed-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ const assert = require('assert');
const zlib = require('zlib');

// For raw deflate encoding, requests for 256-byte windows are rejected as
// invalid by zlib.
// (http://zlib.net/manual.html#Advanced)
assert.throws(() => {
zlib.createDeflateRaw({ windowBits: 8 });
}, /^Error: Init error$/);
// invalid by zlib (http://zlib.net/manual.html#Advanced).
// This check was introduced in vesion 1.2.9 and prior to that there was
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll fix this.

// no such rejection which is the reason for the version check below
// (http://zlib.net/ChangeLog.txt).
if (/^\d+\.\d+\.[9]|\d{2,}$/.test(process.versions.zlib)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this regexp correct? What about a theoretical zlib 1.3.0?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could probably be made stricter, yes. I also don’t quit get the |\d{2,}$ part – are there missing parentheses? /^a|b$/ is grouped as /(^a)|(b$)/, not /^(a|b)$/, but you probably meant something like the latter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richardlau You are right, I missed that :(
@addaleax @richardlau I think I went at this the wrong way trying to match allowed versions. I hope I've managed to simplify the expression by trying to detect an invalid version instead. Let me know what you think.

assert.throws(() => {
zlib.createDeflateRaw({ windowBits: 8 });
}, /^Error: Init error$/);
}

// Regression tests for bugs in the validation logic.

Expand Down