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
28 changes: 24 additions & 4 deletions src/dagre/position/bk.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export {
* single node in the layers being scanned.
*/
function findType1Conflicts(g, layering) {
/** @type {{[nodeId: string | number]: {[nodeId: string | number]: true}}} */
var conflicts = {};

function visitLayer(prevLayer, layer) {
Expand Down Expand Up @@ -78,6 +79,7 @@ function findType1Conflicts(g, layering) {
}

function findType2Conflicts(g, layering) {
/** @type {{[nodeId: string | number]: {[nodeId: string | number]: true}}} */
var conflicts = {};

function scan(south, southPos, southEnd, prevNorthBorder, nextNorthBorder) {
Expand Down Expand Up @@ -129,18 +131,36 @@ function findOtherInnerSegmentNode(g, v) {
}
}

/**
* Sets `conflicts[v][w] = true`, creating objects if needed.
*
* @param {{[nodeId: string | number]: {[nodeId: string | number]: true}}} conflicts - Object to set.
* @param {string | number} v - First Node ID
* @param {string | number} w - Second Node ID
*/
function addConflict(conflicts, v, w) {
if (v > w) {
var tmp = v;
v = w;
w = tmp;
}

var conflictsV = conflicts[v];
if (!conflictsV) {
conflicts[v] = conflictsV = {};
if (!Object.prototype.hasOwnProperty.call(conflicts, v)) {
// can't use conflicts[v] = {} since it's unsafe if v = `__proto__`
Object.defineProperty(conflicts, v, {
enumerable: true,
configurable: true,
value: {},
writable: true,
});
Comment thread
aloisklink marked this conversation as resolved.
}
conflictsV[w] = true;
var conflictsV = conflicts[v];
Object.defineProperty(conflictsV, w, {
enumerable: true,
configurable: true,
value: true,
Comment thread
aloisklink marked this conversation as resolved.
writable: true,
});
}

function hasConflict(conflicts, v, w) {
Expand Down
7 changes: 7 additions & 0 deletions src/dagre/position/bk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ describe('position/bk', function () {
expect(hasConflict(conflicts, 'a', 'b')).to.be.true;
expect(hasConflict(conflicts, 'a', 'c')).to.be.true;
});

it('works for nodes named __proto__', function () {
var conflicts = {};
addConflict(conflicts, '__proto__', 'myAdminKey');
expect(hasConflict(conflicts, '__proto__', 'myAdminKey')).to.be.true;
expect({}).not.to.have.property('myAdminKey');
});
});

describe('verticalAlignment', function () {
Expand Down