From 4697daf5bf1468ebad56387979c95c1b7e1bee34 Mon Sep 17 00:00:00 2001 From: cherenkov Date: Sun, 18 Oct 2026 08:07:03 +0900 Subject: [PATCH] Ensure blur reports the received value for invalid sigma `sigma` was declared without an initial value, so validation errors for `blur({ sigma: 'x' })` and `blur('5')` always reported "received undefined of type undefined". Initialise `sigma` from `options` and pass `options.sigma` when validating the object form. Co-Authored-By: Claude Opus 5.5 --- lib/operation.mjs | 8 +++----- test/unit/blur.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/operation.mjs b/lib/operation.mjs index d10aa8d00..5c788b46f 100644 --- a/lib/operation.mjs +++ b/lib/operation.mjs @@ -379,12 +379,10 @@ function median (size) { * @throws {Error} Invalid parameters */ function blur (options) { - let sigma; - if (is.number(options)) { - sigma = options; - } else if (is.plainObject(options)) { + let sigma = options; + if (is.plainObject(options)) { if (!is.number(options.sigma)) { - throw is.invalidParameterError('options.sigma', 'number between 0.3 and 1000', sigma); + throw is.invalidParameterError('options.sigma', 'number between 0.3 and 1000', options.sigma); } sigma = options.sigma; if ('precision' in options) { diff --git a/test/unit/blur.js b/test/unit/blur.js index 13f010124..dfddea94e 100644 --- a/test/unit/blur.js +++ b/test/unit/blur.js @@ -151,4 +151,18 @@ suite('Blur', () => { sharp(fixtures.inputJpg).blur({ precision: 'invalid' }); }, /Expected number between 0.3 and 1000 for options.sigma but received undefined of type undefined/); }); + + test('invalid options.sigma', (t) => { + t.plan(1); + t.assert.throws(() => { + sharp(fixtures.inputJpg).blur({ sigma: 'x' }); + }, /Expected number between 0.3 and 1000 for options.sigma but received x of type string/); + }); + + test('invalid sigma', (t) => { + t.plan(1); + t.assert.throws(() => { + sharp(fixtures.inputJpg).blur('5'); + }, /Expected number between 0.3 and 1000 for sigma but received 5 of type string/); + }); });