未验证 提交 7887f27a 编写于 作者: Y Yi Shen 提交者: GitHub

Merge pull request #12380 from susiwen8/target

Fix potential security risk
...@@ -21,6 +21,7 @@ import * as zrUtil from 'zrender/src/core/util'; ...@@ -21,6 +21,7 @@ import * as zrUtil from 'zrender/src/core/util';
import ChartView from '../../view/Chart'; import ChartView from '../../view/Chart';
import SunburstPiece from './SunburstPiece'; import SunburstPiece from './SunburstPiece';
import DataDiffer from '../../data/DataDiffer'; import DataDiffer from '../../data/DataDiffer';
import {windowOpen} from '../../util/format';
var ROOT_TO_NODE_ACTION = 'sunburstRootToNode'; var ROOT_TO_NODE_ACTION = 'sunburstRootToNode';
...@@ -206,7 +207,7 @@ var SunburstView = ChartView.extend({ ...@@ -206,7 +207,7 @@ var SunburstView = ChartView.extend({
if (link) { if (link) {
var linkTarget = itemModel.get('target', true) var linkTarget = itemModel.get('target', true)
|| '_blank'; || '_blank';
window.open(link, linkTarget); windowOpen(link, linkTarget);
} }
} }
targetFound = true; targetFound = true;
......
...@@ -28,6 +28,7 @@ import BoundingRect from 'zrender/src/core/BoundingRect'; ...@@ -28,6 +28,7 @@ import BoundingRect from 'zrender/src/core/BoundingRect';
import * as matrix from 'zrender/src/core/matrix'; import * as matrix from 'zrender/src/core/matrix';
import * as animationUtil from '../../util/animation'; import * as animationUtil from '../../util/animation';
import makeStyleMapper from '../../model/mixin/makeStyleMapper'; import makeStyleMapper from '../../model/mixin/makeStyleMapper';
import {windowOpen} from '../../util/format';
var bind = zrUtil.bind; var bind = zrUtil.bind;
var Group = graphic.Group; var Group = graphic.Group;
...@@ -544,7 +545,7 @@ export default echarts.extendChartView({ ...@@ -544,7 +545,7 @@ export default echarts.extendChartView({
var itemModel = node.hostTree.data.getItemModel(node.dataIndex); var itemModel = node.hostTree.data.getItemModel(node.dataIndex);
var link = itemModel.get('link', true); var link = itemModel.get('link', true);
var linkTarget = itemModel.get('target', true) || 'blank'; var linkTarget = itemModel.get('target', true) || 'blank';
link && window.open(link, linkTarget); link && windowOpen(link, linkTarget);
} }
} }
......
...@@ -21,6 +21,7 @@ import * as zrUtil from 'zrender/src/core/util'; ...@@ -21,6 +21,7 @@ import * as zrUtil from 'zrender/src/core/util';
import * as echarts from '../echarts'; import * as echarts from '../echarts';
import * as graphic from '../util/graphic'; import * as graphic from '../util/graphic';
import {getLayoutRect} from '../util/layout'; import {getLayoutRect} from '../util/layout';
import {windowOpen} from '../util/format';
// Model // Model
echarts.extendComponentModel({ echarts.extendComponentModel({
...@@ -143,12 +144,12 @@ echarts.extendComponentView({ ...@@ -143,12 +144,12 @@ echarts.extendComponentView({
if (link) { if (link) {
textEl.on('click', function () { textEl.on('click', function () {
window.open(link, '_' + titleModel.get('target')); windowOpen(link, '_' + titleModel.get('target'));
}); });
} }
if (sublink) { if (sublink) {
subTextEl.on('click', function () { subTextEl.on('click', function () {
window.open(sublink, '_' + titleModel.get('subtarget')); windowOpen(link, '_' + titleModel.get('subtarget'));
}); });
} }
......
...@@ -23,7 +23,7 @@ import * as numberUtil from './number'; ...@@ -23,7 +23,7 @@ import * as numberUtil from './number';
// import Text from 'zrender/src/graphic/Text'; // import Text from 'zrender/src/graphic/Text';
/** /**
* 每三位默认加,格式化 * add commas after every three numbers
* @param {string|number} x * @param {string|number} x
* @return {string} * @return {string}
*/ */
...@@ -275,3 +275,19 @@ export function getTextRect( ...@@ -275,3 +275,19 @@ export function getTextRect(
text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate
); );
} }
/**
* open new tab
* @param {string} link url
* @param {string} target blank or self
*/
export function windowOpen(link, target) {
if (target === '_blank' || target === 'blank') {
var blank = window.open();
blank.opener = null;
blank.location = link;
}
else {
window.open(link, target);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册