Skip to content

Commit

Permalink
fix(outline): prevent access of non-existing connection bounds
Browse files Browse the repository at this point in the history
Closes #822
  • Loading branch information
nikku committed Nov 7, 2023
1 parent 88c11a4 commit 790fc34
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
26 changes: 15 additions & 11 deletions lib/features/outline/Outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,20 @@ export default function Outline(eventBus, styles) {

var self = this;

function createOutline(gfx, element) {
/**
* @param {SVGElement} gfx
*
* @return {SVGElement} outline
*/
function createOutline(gfx) {
var outline = svgCreate('rect');

svgAttr(outline, assign({
x: - self.offset,
y: - self.offset,
x: 0,
y: 0,
rx: 4,
width: element.width + self.offset * 2,
height: element.height + self.offset * 2
width: 100,
height: 100
}, OUTLINE_STYLE));

return outline;
Expand All @@ -69,12 +74,11 @@ export default function Outline(eventBus, styles) {
var outline = domQuery('.djs-outline', gfx);

if (!outline) {
outline = self.getOutline(element) || createOutline(gfx, element);
outline = self.getOutline(element) || createOutline(gfx);
svgAppend(gfx, outline);

} else {
self.updateShapeOutline(outline, element);
}

self.updateShapeOutline(outline, element);
});

eventBus.on([ 'connection.added', 'connection.changed' ], function(event) {
Expand All @@ -84,7 +88,7 @@ export default function Outline(eventBus, styles) {
var outline = domQuery('.djs-outline', gfx);

if (!outline) {
outline = createOutline(gfx, element);
outline = createOutline(gfx);
svgAppend(gfx, outline);
}

Expand Down Expand Up @@ -128,7 +132,7 @@ Outline.prototype.updateShapeOutline = function(outline, element) {
*
* @param {SVGElement} outline
* @param {Element} connection
**/
*/
Outline.prototype.updateConnectionOutline = function(outline, connection) {
var bbox = getBBox(connection);

Expand Down
20 changes: 17 additions & 3 deletions test/spec/features/outline/OutlineSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {

import {
classes as svgClasses,
create as svgCreate
create as svgCreate,
attr as svgAttr
} from 'tiny-svg';


Expand Down Expand Up @@ -47,7 +48,11 @@ describe('features/outline/Outline', function() {
var outline = domQuery('.djs-outline', gfx);

expect(outline).to.exist;
expect(svgClasses(gfx).has('selected')).to.be.true; // Outline class is set

expect(svgAttr(outline, 'x')).to.exist;

// outline class is set
expect(svgClasses(gfx).has('selected')).to.be.true;
}));


Expand All @@ -64,7 +69,11 @@ describe('features/outline/Outline', function() {
var outline = domQuery('.djs-outline', gfx);

expect(outline).to.exist;
expect(svgClasses(gfx).has('selected')).to.be.true; // Outline class is set

expect(svgAttr(outline, 'x')).to.exist;

// outline class is set
expect(svgClasses(gfx).has('selected')).to.be.true;
}));

});
Expand Down Expand Up @@ -107,6 +116,11 @@ describe('features/outline/Outline', function() {
return svgCreate('rect');
}
}

updateOutline(element, gfx) {

// noop
}
}

it('should register provider', inject(function(outline) {
Expand Down

0 comments on commit 790fc34

Please sign in to comment.