parent
be42a3b9c8
commit
c56dd23358
@ -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.
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -27,6 +27,7 @@ import "./tests/Categories.mjs";
|
||||
import "./tests/ToHTMLEntity.mjs";
|
||||
import "./tests/lib/BigIntUtils.mjs";
|
||||
import "./tests/lib/ChartsProtocolPrototypePollution.mjs";
|
||||
import "./tests/ParseQRCode.mjs";
|
||||
|
||||
const testStatus = {
|
||||
allTestsPassing: true,
|
||||
|
||||
35
tests/node/tests/ParseQRCode.mjs
Normal file
35
tests/node/tests/ParseQRCode.mjs
Normal file
@ -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)."
|
||||
);
|
||||
}),
|
||||
]);
|
||||
Loading…
x
Reference in New Issue
Block a user