Compare commits
8 Commits
1a5c05d2a9
...
0e7caca935
Author | SHA1 | Date |
---|---|---|
pmario | 0e7caca935 | |
pmario | a53c6b5e5c | |
pmario | b4c369adc4 | |
pmario | 3c888992a8 | |
pmario | bb9c991ce3 | |
pmario | 05f1ba20ca | |
pmario | d28271620b | |
pmario | 1a4c114ecb |
|
@ -0,0 +1,26 @@
|
|||
/*\
|
||||
title: $:/core/modules/macros/parent-ancestorcount-dom.js
|
||||
type: application/javascript
|
||||
module-type: macro
|
||||
|
||||
Macro to return the parent widget this.ancestors variable
|
||||
|
||||
\*/
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Information about this macro
|
||||
*/
|
||||
|
||||
exports.name = "parent-ancestorcount-dom";
|
||||
|
||||
exports.params = [];
|
||||
|
||||
/*
|
||||
Run the macro
|
||||
*/
|
||||
exports.run = function() {
|
||||
return (this.parentWidget) ? this.parentWidget.getAncestorCountDom() + "" : "";
|
||||
};
|
|
@ -15,6 +15,7 @@ Browse widget for browsing for files to import
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var BrowseWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
|||
var Popup = require("$:/core/modules/utils/dom/popup.js");
|
||||
|
||||
var ButtonWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
@ -56,6 +57,7 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
|||
this.execute();
|
||||
// Check "button in button". Return early with an error message
|
||||
// This check also prevents fatal recursion errors using the transclusion widget
|
||||
if(this.getVariable("tv-limit-nested-buttons") === "yes") {
|
||||
if(this.isNestedButton()) {
|
||||
var domNode = this.document.createElement("span");
|
||||
var textNode = this.document.createTextNode($tw.language.getString("Error/RecursiveButton"));
|
||||
|
@ -65,6 +67,7 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
|||
this.domNodes.push(domNode);
|
||||
return; // an error message
|
||||
}
|
||||
}
|
||||
// Create element
|
||||
if(this.buttonTag && $tw.config.htmlUnsafeElements.indexOf(this.buttonTag) === -1) {
|
||||
tag = this.buttonTag;
|
||||
|
@ -72,7 +75,7 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
|||
domNode = this.document.createElement(tag);
|
||||
this.domNode = domNode;
|
||||
// Assign classes
|
||||
var classes = this["class"].split(" ") || [],
|
||||
var classes = (this["class"]) ? this["class"].split(" ") : [],
|
||||
isPoppedUp = (this.popup || this.popupTitle) && this.isPoppedUp();
|
||||
if(this.selectedClass) {
|
||||
if((this.set || this.setTitle) && this.setTo && this.isSelected()) {
|
||||
|
@ -86,7 +89,9 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
|||
if(isPoppedUp) {
|
||||
$tw.utils.pushTop(classes,"tc-popup-handle");
|
||||
}
|
||||
if(classes.length > 0) {
|
||||
domNode.className = classes.join(" ");
|
||||
}
|
||||
// Assign data- attributes
|
||||
this.assignAttributes(domNode,{
|
||||
sourcePrefix: "data-",
|
||||
|
|
|
@ -15,6 +15,7 @@ Checkbox widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var CheckboxWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Code block node widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var CodeBlockWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ var Widget = require("$:/core/modules/widgets/widget.js").widget,
|
|||
dmp = require("$:/core/modules/utils/diff-match-patch/diff_match_patch.js");
|
||||
|
||||
var DiffTextWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Draggable widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var DraggableWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Droppable widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var DroppableWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ var IMPORT_TITLE = "$:/Import";
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var DropZoneWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ var LINE_WIDTH_TITLE = "$:/config/BitmapEditor/LineWidth",
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var EditBitmapWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Widget to display an editable keyboard shortcut
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var EditShortcutWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Element widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var ElementWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Error widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var ErrorWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Event handler widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var EventWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ The width and height attributes are interpreted as a number of pixels, and do no
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var ImageWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Keyboard shortcut widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var KeyboardWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Link widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var LinkWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Password widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var PasswordWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ Set a field or index at a given tiddler via radio buttons
|
|||
|
||||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
var RadioWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Range widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var RangeWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Raw widget
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var RawWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
|||
var Popup = require("$:/core/modules/utils/dom/popup.js");
|
||||
|
||||
var RevealWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ var DEBOUNCE_INTERVAL = 100; // Delay after last scroll event before updating th
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var ScrollableWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ Select widget:
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var SelectWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ Widget base class
|
|||
|
||||
/* Maximum permitted depth of the widget tree for recursion detection */
|
||||
var MAX_WIDGET_TREE_DEPTH = 1000;
|
||||
var MAX_DOM_TREE_DEPTH = 100;
|
||||
|
||||
/*
|
||||
Create a widget object for a parse tree node
|
||||
|
@ -65,6 +66,23 @@ Widget.prototype.initialise = function(parseTreeNode,options) {
|
|||
}
|
||||
});
|
||||
}
|
||||
// Increment ancestorCountDom if options.hasDom = true otherwise set it to the "old" value
|
||||
this.getAncestorCountDom(options.hasDom);
|
||||
};
|
||||
|
||||
Widget.prototype.getAncestorCountDom = function(createsDomNode) {
|
||||
if(this.ancestorCountDom === undefined) {
|
||||
if(this.parentWidget) {
|
||||
if(createsDomNode) {
|
||||
this.ancestorCountDom = this.parentWidget.getAncestorCountDom() + 1;
|
||||
} else {
|
||||
this.ancestorCountDom = this.parentWidget.getAncestorCountDom();
|
||||
}
|
||||
} else {
|
||||
this.ancestorCountDom = 0;
|
||||
}
|
||||
}
|
||||
return this.ancestorCountDom;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -496,10 +514,18 @@ Widget.prototype.makeChildWidgets = function(parseTreeNodes,options) {
|
|||
this.children = [];
|
||||
var self = this;
|
||||
// Check for too much recursion
|
||||
if(this.getAncestorCount() > this.UNSAFE_max_widget_tree_depth) {
|
||||
this.children.push(this.makeChildWidget({type: "error", attributes: {
|
||||
"$message": {type: "string", value: this.getAncestorCount() + " - " + $tw.language.getString("Error/RecursiveTransclusion")}
|
||||
}}));
|
||||
// if(this.getAncestorCount() > this.UNSAFE_max_widget_tree_depth) {
|
||||
// if(this.getAncestorCount() > MAX_WIDGET_TREE_DEPTH) {
|
||||
if((this.getAncestorCountDom() > MAX_DOM_TREE_DEPTH) || (this.getAncestorCount() > this.UNSAFE_max_widget_tree_depth)) {
|
||||
this.children.push(this.makeChildWidget({
|
||||
type: "error", attributes: {
|
||||
"$message": {
|
||||
type: "string",
|
||||
value: this.getAncestorCount() + " - " + (this.getAncestorCountDom() + 1 ) + " - " +
|
||||
$tw.language.getString("Error/RecursiveTransclusion")
|
||||
}
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
// Create set variable widgets for each variable
|
||||
$tw.utils.each(options.variables,function(value,name) {
|
||||
|
|
|
@ -15,6 +15,7 @@ Widget to wikify text into a variable
|
|||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
|
||||
var WikifyWidget = function(parseTreeNode,options) {
|
||||
options.hasDom = true;
|
||||
this.initialise(parseTreeNode,options);
|
||||
};
|
||||
|
||||
|
|
|
@ -12,4 +12,4 @@ title: Output
|
|||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p><button class=""><button class=""><button class=""><span class="tc-error">Possible Recursive Error: Button in button is not allowed</span></button></button></button></p>
|
||||
<p><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><button><span class="tc-error">202 - 102 - Recursive transclusion error in transclude widget</span></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></button></p>
|
|
@ -12,4 +12,4 @@ title: Output
|
|||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p><button class="">Test Button<button class="">Second button</button></button></p>
|
||||
<p><button>Test Button<button>Second button</button></button></p>
|
|
@ -10,7 +10,9 @@ title: Output
|
|||
title: Button
|
||||
|
||||
<$button><<parent-ancestorcount>></$button>
|
||||
<$button><<parent-ancestorcount-dom>></$button>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>1000 - <button class="">6</button></p>
|
||||
<p>1000 - <button>6</button>
|
||||
<button>2</button></p>
|
|
@ -10,4 +10,4 @@ title: Output
|
|||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p><span class="tc-error">1001 - Recursive transclusion error in transclude widget</span></p>
|
||||
<p><span class="tc-error">1001 - 2 - Recursive transclusion error in transclude widget</span></p>
|
|
@ -157,7 +157,7 @@ describe("Widget module", function() {
|
|||
// Render the widget node to the DOM
|
||||
var wrapper = renderWidgetNode(widgetNode);
|
||||
// Test the rendering
|
||||
expect(wrapper.innerHTML).toBe("<span class=\"tc-error\">1001 - Recursive transclusion error in transclude widget</span>");
|
||||
expect(wrapper.innerHTML).toBe("<span class=\"tc-error\">1001 - 1 - Recursive transclusion error in transclude widget</span>");
|
||||
});
|
||||
|
||||
it("should deal with SVG elements", function() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
created: 20240415102801809
|
||||
modified: 20240418072358045
|
||||
modified: 20240425142244830
|
||||
tags:
|
||||
title: test-collatz
|
||||
type: text/vnd.tiddlywiki
|
||||
|
@ -8,15 +8,12 @@ type: text/vnd.tiddlywiki
|
|||
<% if [<n>match[1]] %>
|
||||
1
|
||||
<% elseif [<n>remainder[2]match[1]] %>
|
||||
<<n>> → <$transclude $variable="collatz" n = {{{ [<n>multiply[3]add[1]] }}}/>
|
||||
<<n>> - ^^@@<<parent-ancestorcount>>@@^^ → <$transclude $variable="collatz" n = {{{ [<n>multiply[3]add[1]] }}}/>
|
||||
<% else %>
|
||||
<<n>> → <$transclude $variable="collatz" n = {{{ [<n>divide[2]] }}}/>
|
||||
<<n>> - ^^@@<<parent-ancestorcount>>@@^^ → <$transclude $variable="collatz" n = {{{ [<n>divide[2]] }}}/>
|
||||
<% endif %>
|
||||
\end
|
||||
|
||||
\procedure test(x:10)
|
||||
<<set_UNSAFE_max_widget_tree_depth 2000>>
|
||||
<$transclude $variable=collatz n=<<x>>/>
|
||||
\end
|
||||
<<set_UNSAFE_max_widget_tree_depth 5000>>
|
||||
|
||||
<<test 77031>>
|
||||
<<collatz 9780657630>>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
created: 20240425123038613
|
||||
modified: 20240425142745826
|
||||
tags:
|
||||
title: test-div
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
||||
<div><div><div><div><div><div><div><div><div><div>10
|
|
@ -1,5 +1,5 @@
|
|||
created: 20240417070900019
|
||||
modified: 20240418072413015
|
||||
modified: 20240425133540950
|
||||
tags:
|
||||
title: test-new-set-get-macros
|
||||
type: text/vnd.tiddlywiki
|
||||
|
@ -8,6 +8,8 @@ type: text/vnd.tiddlywiki
|
|||
|
||||
ancestor count: <<parent-ancestorcount>>
|
||||
|
||||
ancestor dom count: <<parent-ancestorcount-dom>>
|
||||
|
||||
UNSAFE_max_widget_tree_depth: <<get_UNSAFE_max_widget_tree_depth>>
|
||||
|
||||
<<set_UNSAFE_max_widget_tree_depth 2000>>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
created: 20240425142531569
|
||||
modified: 20240425142540369
|
||||
tags:
|
||||
title: test-recursive button limited
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
\whitespace trim
|
||||
\define tv-limit-nested-buttons() yes
|
||||
|
||||
<<parent-ancestorcount-dom>>
|
||||
|
||||
<$button>
|
||||
<$transclude/>
|
||||
</$button>
|
|
@ -1,10 +1,13 @@
|
|||
created: 20240415124530887
|
||||
modified: 20240416111839904
|
||||
modified: 20240425142547412
|
||||
tags:
|
||||
title: test-recursive button
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
\whitespace trim
|
||||
|
||||
<<parent-ancestorcount-dom>>
|
||||
|
||||
<$button>
|
||||
<$transclude/>
|
||||
</$button>
|
Loading…
Reference in New Issue