Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed RSoD error with moduleproperty filter operator #8958

Merged
merged 2 commits into from
Mar 6, 2025
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
13 changes: 10 additions & 3 deletions core/modules/filters/moduleproperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ Export our filter function
exports.moduleproperty = function(source,operator,options) {
var results = [];
source(function(tiddler,title) {
var value = require(title)[operator.operand || ""];
if(value !== undefined) {
results.push(value);
try {
var value = require(title)[operator.operand || ""];
if(value !== undefined) {
if(typeof value !== "string") {
value = JSON.stringify(value);
}
results.push(value);
}
} catch(e) {
// Do nothing. It probably wasn't a module.
}
});
results.sort();
Expand Down
10 changes: 10 additions & 0 deletions editions/test/tiddlers/tests/test-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,16 @@ Tests the filtering mechanism.
expect(wiki.filterTiddlers("[[<>:\"/\\|?*]encodeuricomponent[]]").join(",")).toBe("%3C%3E%3A%22%2F%5C%7C%3F%2A");
});

it("should handle the moduleproperty operator", function() {
// We don't need to confirm them all, only it it finds at least one module name that we're sure is there.
expect(wiki.filterTiddlers("[[macro]modules[]moduleproperty[name]]")).toContain("qualify");
// No such property. Nothing to return.
expect(wiki.filterTiddlers("[[macro]modules[]moduleproperty[nonexistent]]").length).toBe(0);
// No such tiddlers. Nothing to return.
expect(wiki.filterTiddlers("[[nonexistent]moduleproperty[name]]").length).toBe(0);
// Non string properties should get toStringed.
expect(wiki.filterTiddlers("[[$:/core/modules/commands/init.js]moduleproperty[info]]").join(" ")).toBe('{"name":"init","synchronous":true}');
});
}

});
Expand Down