diff --git a/src/core/operations/ParseQRCode.mjs b/src/core/operations/ParseQRCode.mjs index 89eaddee98..addc1f17d2 100644 --- a/src/core/operations/ParseQRCode.mjs +++ b/src/core/operations/ParseQRCode.mjs @@ -33,15 +33,11 @@ class ParseQRCode extends Operation { value: false, }, ]; - this.checks = [ - { - pattern: - "^(?:\\xff\\xd8\\xff|\\x89\\x50\\x4e\\x47|\\x47\\x49\\x46|.{8}\\x57\\x45\\x42\\x50|\\x42\\x4d)", - flags: "", - args: [false], - useful: true, - }, - ]; + // No Magic checks: detecting a QR code in arbitrary image data requires + // actually attempting to parse one, which is expensive and produces + // spurious "Could not read a QR code from the image" log messages for + // any image input via Magic. Users can add Parse QR Code manually when + // they know the image contains a QR code. See issue #2610. } /** diff --git a/tests/node/index.mjs b/tests/node/index.mjs index 360bf481de..d9ac8f63cf 100644 --- a/tests/node/index.mjs +++ b/tests/node/index.mjs @@ -26,6 +26,7 @@ import "./tests/Utils.mjs"; import "./tests/Categories.mjs"; import "./tests/lib/BigIntUtils.mjs"; import "./tests/lib/ChartsProtocolPrototypePollution.mjs"; +import "./tests/ParseQRCode.mjs"; const testStatus = { allTestsPassing: true, diff --git a/tests/node/tests/ParseQRCode.mjs b/tests/node/tests/ParseQRCode.mjs new file mode 100644 index 0000000000..c063946a01 --- /dev/null +++ b/tests/node/tests/ParseQRCode.mjs @@ -0,0 +1,35 @@ +/** + * ParseQRCode API tests. + * + * @author Sanjays2402 + * @copyright Crown Copyright 2026 + * @license Apache-2.0 + */ +import TestRegister from "../../lib/TestRegister.mjs"; +import OperationConfig from "../../../src/core/config/OperationConfig.json" with { type: "json" }; +import it from "../assertionHandler.mjs"; +import assert from "assert"; + +TestRegister.addApiTests([ + /* + * Regression test for #2610. + * + * Parse QR Code used to declare a `checks` regex that matched any JPEG, + * PNG, GIF, WEBP or BMP magic bytes. Magic aggregates every operation + * with a `checks` property, so any image input ran through a full QR + * parse attempt, which in turn emitted a "Could not read a QR code from + * the image" warning to the browser console for every image. There is + * no cheap way to detect a QR code without attempting a full parse, so + * Parse QR Code must not participate in Magic; users can add it + * manually when they know an image contains a QR code. + */ + it("Parse QR Code: must not participate in Magic (#2610)", () => { + const op = OperationConfig["Parse QR Code"]; + assert(op, "Parse QR Code operation is missing from OperationConfig"); + assert( + !op.checks || op.checks.length === 0, + "Parse QR Code must not declare `checks`; otherwise Magic will run a " + + "QR parse on every image and spam the console (see issue #2610)." + ); + }), +]);