Skip to content
Merged
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
497 changes: 260 additions & 237 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
"compression-webpack-plugin": "^12.0.0",
"copy-webpack-plugin": "^14.0.0",
"core-js": "^3.50.0",
"cspell": "^10.0.1",
"cspell": "^10.2.2",
"css-loader": "^7.1.4",
"eslint": "^10.8.1",
"eslint-plugin-jsdoc": "^64.2.1",
"glob": "^13.0.6",
"globals": "^17.11.0",
"globals": "^17.12.0",
"grunt": "^1.6.3",
"grunt-chmod": "~1.1.1",
"grunt-concurrent": "^3.0.0",
Expand All @@ -87,7 +87,7 @@
"postcss-loader": "^8.2.1",
"prompt": "^1.3.0",
"sitemap": "^9.0.1",
"terser": "^5.50.0",
"terser": "^5.51.2",
"webpack": "^5.109.2",
"webpack-bundle-analyzer": "^5.3.2",
"webpack-dev-server": "^5.2.6",
Expand All @@ -98,7 +98,7 @@
"@alexaltea/capstone-js": "^3.0.5",
"@astronautlabs/amf": "^0.0.6",
"@blu3r4y/lzma": "^2.3.3",
"@noble/hashes": "2.3.0",
"@noble/hashes": "2.4.0",
"@wavesenterprise/crypto-gost-js": "^2.1.0-RC1",
"@xmldom/xmldom": "^0.8.15",
"argon2-browser": "^1.18.0",
Expand Down Expand Up @@ -142,7 +142,7 @@
"jquery": "3.7.1",
"js-ascon": "^1.3.0",
"js-sha3": "^0.13.0",
"js-yaml": "^5.3.0",
"js-yaml": "^5.4.1",
"jsesc": "^3.1.0",
"json5": "^2.2.3",
"jsonata": "^2.2.2",
Expand Down Expand Up @@ -173,7 +173,7 @@
"path": "^0.12.7",
"popper.js": "^1.16.1",
"process": "^0.11.10",
"protobufjs": "^8.7.2",
"protobufjs": "^8.8.0",
"punycode.js": "^2.3.1",
"qr-image": "^3.2.0",
"reflect-metadata": "^0.2.2",
Expand Down
8 changes: 5 additions & 3 deletions src/core/Dish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ class Dish {
Object.prototype.hasOwnProperty.call(dishOrInput, "value") &&
Object.prototype.hasOwnProperty.call(dishOrInput, "type")) {
this.set(dishOrInput.value, dishOrInput.type);
// input and type defined separately
} else if (dishOrInput && type !== null) {
// input and type defined separately. 0 is falsy but is a valid value;
// Boolean and other unsupported falsy inputs keep the previous
// empty-dish behaviour.
} else if ((dishOrInput || dishOrInput === 0) && type !== null) {
this.set(dishOrInput, type);
// No type declared, so infer it.
} else if (dishOrInput) {
} else if (dishOrInput || dishOrInput === 0) {
const inferredType = Dish.typeEnum(dishOrInput.constructor.name);
this.set(dishOrInput, inferredType);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/operations/RenderMarkdown.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class RenderMarkdown extends Operation {
const token = tokens[idx];
if (token.attrIndex("target") >= 0) {
// Target attribute already set, do not replace.
return;
return defaultRender(tokens, idx, options, env, self);
}
token.attrPush(["target", "_blank"]); // add new attribute

Expand Down
2 changes: 1 addition & 1 deletion src/node/api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function transformArgs(opArgsList, newArgs) {
* @param input
*/
function ensureIsDish(input) {
if (!input) {
if (input === undefined || input === null) {
return new NodeDish();
}

Expand Down
23 changes: 23 additions & 0 deletions tests/node/tests/NodeDish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs from "fs";
import BigNumber from "bignumber.js";

import { Dish, toBase32, SHA3 } from "../../../src/node/index.mjs";
import chef from "../../../src/node/index.mjs";
import File from "../../../src/node/File.mjs";
import TestRegister from "../../lib/TestRegister.mjs";

Expand Down Expand Up @@ -232,4 +233,26 @@ TestRegister.addApiTests([
const actual = Array.prototype.slice.call(dataArray).map(c => String.fromCharCode(c)).join("");
assert.strictEqual(actual, "abcdefghijk");
}),

it("Dish: numeric 0 input should not be treated as an empty dish", () => {
const dish = new Dish(0);
assert.strictEqual(dish.type, Dish.NUMBER);
assert.strictEqual(dish.get(Dish.NUMBER), 0);
}),

it("chef: numeric 0 input should be preserved", async () => {
assert.strictEqual(chef.ADD(0, {key: "4"}).toString(), "4");
assert.strictEqual(chef.toHex(0).toString(), "30");
assert.strictEqual((await chef.bake(0, [chef.toHex])).toString(), "30");
}),

it("Dish: boolean false input should produce an empty dish, not throw", () => {
const dish = new Dish(false);
assert.strictEqual(dish.type, Dish.ARRAY_BUFFER);
assert.strictEqual(dish.value.byteLength, 0);
}),

it("chef: boolean false input should still produce an empty dish", async () => {
assert.strictEqual((await chef.bake(false)).toString(), "");
}),
]);
15 changes: 15 additions & 0 deletions tests/node/tests/operations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import {
import chef from "../../../src/node/index.mjs";
import TestRegister from "../../lib/TestRegister.mjs";
import File from "../../../src/node/File.mjs";
import MarkdownIt from "markdown-it";
import Token from "markdown-it/lib/token.mjs";
import RenderMarkdown from "../../../src/core/operations/RenderMarkdown.mjs";

global.File = File;

Expand Down Expand Up @@ -1201,6 +1204,18 @@ ExifImageHeight: 57`);

}),

it("Render Markdown: makeLinksOpenInNewTab preserves tokens with pre-existing target", () => {
const op = new RenderMarkdown();
const md = new MarkdownIt();
op.makeLinksOpenInNewTab(md);

const token = new Token("link_open", "a", 1);
token.attrs = [["href", "https://example.com"], ["target", "_self"]];
const tokens = [token];

const rendered = md.renderer.rules.link_open(tokens, 0, {}, {}, md.renderer);
assert.strictEqual(rendered, '<a href="https://example.com" target="_self">');
}),

]);