Skip to content

Commit

Permalink
Fix/defensive code for curve types (#115)
Browse files Browse the repository at this point in the history
* Validate line type before calling radius strategy

* Selectable options link types more secure sandbox
  • Loading branch information
danielcaldas authored Sep 29, 2018
1 parent 52df1b4 commit bab583f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions sandbox/utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
/*eslint require-jsdoc: 0, valid-jsdoc: 0, no-undef: 0, no-empty: 0, no-console: 0*/
import queryString from 'query-string';
import { LINE_TYPES } from '../src/components/link/link.const';

/**
* This two functions generate the react-jsonschema-form
* schema from some passed graph configuration.
*/
function formMap(k, v) {
// customized props
switch (k) {
case 'link.type': {
return {
type: 'array',
title: 'link.type',
items: {
enum: Object.keys(LINE_TYPES)
},
uniqueItems: true
};
}
}

return {
title: k,
type: typeof v,
Expand Down
3 changes: 2 additions & 1 deletion src/components/link/link.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ function getRadiusStrategy(type) {
function buildLinkPathDefinition({ source = {}, target = {} }, type = LINE_TYPES.STRAIGHT) {
const { x: sx, y: sy } = source;
const { x: tx, y: ty } = target;
const radius = getRadiusStrategy(type)(sx, sy, tx, ty);
const validType = LINE_TYPES[type] || LINE_TYPES.STRAIGHT;
const radius = getRadiusStrategy(validType)(sx, sy, tx, ty);

return `M${sx},${sy}A${radius},${radius} 0 0,1 ${tx},${ty}`;
}
Expand Down

0 comments on commit bab583f

Please sign in to comment.