Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 5 additions & 9 deletions src/core/operations/ParseQRCode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 35 additions & 0 deletions tests/node/tests/ParseQRCode.mjs
Original file line number Diff line number Diff line change
@@ -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)."
);
}),
]);