mirror of
https://github.com/Fdawgs/node-poppler.git
synced 2026-07-02 08:27:45 +08:00
fix(index): skip version checks for false boolean options (#751)
* fix(index): skip version checks for `false` boolean options * test(index): version skip check
This commit is contained in:
+11
-9
@@ -609,16 +609,18 @@ function parseOptions(acceptedOptions, options, version) {
|
||||
const optionType = typeof option;
|
||||
|
||||
if (acceptedOption.type === optionType) {
|
||||
// Skip boolean options if false
|
||||
if (acceptedOption.type !== "boolean" || option) {
|
||||
// Arg will be empty for some non-standard options
|
||||
if (acceptedOption.arg !== "") {
|
||||
args.push(acceptedOption.arg);
|
||||
}
|
||||
// Boolean options set to false won't be passed to the binary; skip arg and version checks
|
||||
if (acceptedOption.type === "boolean" && !option) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (optionType !== "boolean") {
|
||||
args.push(option);
|
||||
}
|
||||
// Arg will be empty for some non-standard options
|
||||
if (acceptedOption.arg !== "") {
|
||||
args.push(acceptedOption.arg);
|
||||
}
|
||||
|
||||
if (optionType !== "boolean") {
|
||||
args.push(option);
|
||||
}
|
||||
} else {
|
||||
invalidArgs.push(
|
||||
|
||||
@@ -1237,6 +1237,25 @@ describe("Node-Poppler module", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("Does not reject with an Error object if option provided is only available in a later version of the pdftoppm binary than what was provided, but is set to false", async () => {
|
||||
const options = {
|
||||
printProgress: false,
|
||||
};
|
||||
|
||||
if (lt(version, "21.03.0", { loose: true })) {
|
||||
const res = await poppler.pdfToPpm(
|
||||
file,
|
||||
`${testDirectory}pdf_1.3_NHS_Constitution`,
|
||||
options
|
||||
);
|
||||
|
||||
expect(res).toBe("No Error");
|
||||
await expect(
|
||||
access(`${testDirectory}pdf_1.3_NHS_Constitution-01.ppm`)
|
||||
).resolves.toBeUndefined();
|
||||
}
|
||||
});
|
||||
|
||||
it("Rejects with an Error object if invalid option is passed to function", async () => {
|
||||
const options = {
|
||||
middlePageToConvert: "test",
|
||||
|
||||
Reference in New Issue
Block a user