diff --git a/lib/zlib.js b/lib/zlib.js index 056b1a13a17..d4f2446a597 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -969,6 +969,8 @@ function crc32(data, value = 0) { throw new ERR_INVALID_ARG_TYPE('data', ['Buffer', 'TypedArray', 'DataView', 'string'], data); } validateUint32(value, 'value'); + // Coerce -0 to +0. + value += 0; return crc32Native(data, value); } diff --git a/test/parallel/test-zlib-negative-zero.js b/test/parallel/test-zlib-negative-zero.js new file mode 100644 index 00000000000..dc9cc3175d2 --- /dev/null +++ b/test/parallel/test-zlib-negative-zero.js @@ -0,0 +1,8 @@ +'use strict'; + +require('../common'); + +const assert = require('assert'); +const zlib = require('zlib'); + +assert.strictEqual(zlib.crc32('', -0), zlib.crc32('', 0));