Copilot commented on code in PR #21871:
URL: https://github.com/apache/echarts/pull/21871#discussion_r4797696424


##########
src/component/tooltip/TooltipHTMLContent.ts:
##########
@@ -32,78 +32,93 @@ import type CanvasPainter from 'zrender/src/canvas/Painter';
 import type SVGPainter from 'zrender/src/svg/Painter';
 import {
     shouldTooltipConfine,
-    toCSSVendorPrefix,
     getComputedStyle,
-    TRANSFORM_VENDOR,
-    TRANSITION_VENDOR
 } from './helper';
 import { getPaddingFromTooltipModel } from './tooltipMarkup';
+import { CSS_TRANSFORM_VENDOR, CSS_TRANSITION_VENDOR } from 
'../../util/vendor';
+import { mathRound } from '../../util/number';
 
 /* global document, window */
 
-const CSS_TRANSITION_VENDOR = toCSSVendorPrefix(TRANSITION_VENDOR, 
'transition');
-const CSS_TRANSFORM_VENDOR = toCSSVendorPrefix(TRANSFORM_VENDOR, 'transform');
-
 // eslint-disable-next-line
 const gCssText = 
`position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;${env.transform3dSupported
 ? 'will-change:transform;' : ''}`;
 
-function mirrorPos(pos: string): string {
-    pos = pos === 'left'
+/**
+ * SECURITY: This method must guarantee the returned value is only 'left' | 
'right' | 'top' | 'bottom',
+ * otherwise, malicious CSS declaration injections may be introduced via 
`TooltipOption['position']`.
+ */
+function mirrorAndSanitizePos(pos: TooltipOption['position']): 'left' | 
'right' | 'top' | 'bottom' {
+    return pos === 'left'
         ? 'right'
         : pos === 'right'
         ? 'left'
         : pos === 'top'
         ? 'bottom'
         : 'top';
-    return pos;
 }
 
 function assembleArrow(
+    el: HTMLDivElement,
     tooltipModel: Model<TooltipOption>,
     borderColor: ZRColor,
-    arrowPosition: TooltipOption['position']
-) {
-    if (!isString(arrowPosition) || arrowPosition === 'inside') {
-        return '';
+    arrowPosOption: TooltipOption['position']
+): void {
+    if (!el.childNodes.length // no arrow if empty
+        || !isString(arrowPosOption)
+        || arrowPosOption === 'inside'
+        || tooltipModel.get('trigger') !== 'item'
+        || shouldTooltipConfine(tooltipModel)
+    ) {
+        return;
     }
 
+    const arrowPos = mirrorAndSanitizePos(arrowPosOption);
+
+    const arrowEl = document.createElement('div');
+    const arrowCSSStyle = arrowEl.style;
+
     const backgroundColor = tooltipModel.get('backgroundColor');
     const borderWidth = tooltipModel.get('borderWidth');
 
     borderColor = convertToColorString(borderColor);
-    const arrowPos = mirrorPos(arrowPosition);
     const arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
-    let positionStyle = '';
-    let transformStyle = CSS_TRANSFORM_VENDOR + ':';
     let rotateDeg;
     if (indexOf(['left', 'right'], arrowPos) > -1) {
-        positionStyle += 'top:50%';
-        transformStyle += `translateY(-50%) rotate(${rotateDeg = arrowPos === 
'left' ? -225 : -45}deg)`;
+        arrowCSSStyle.top = '50%';
+        arrowCSSStyle[CSS_TRANSFORM_VENDOR.c as 'transform'] =
+            `translateY(-50%) rotate(${rotateDeg = arrowPos === 'left' ? -225 
: -45}deg)`;
     }
     else {
-        positionStyle += 'left:50%';
-        transformStyle += `translateX(-50%) rotate(${rotateDeg = arrowPos === 
'top' ? 225 : 45}deg)`;
+        arrowCSSStyle.left = '50%';
+        arrowCSSStyle[CSS_TRANSFORM_VENDOR.c as 'transform'] =
+            `translateX(-50%) rotate(${rotateDeg = arrowPos === 'top' ? 225 : 
45}deg)`;
     }
+
     const rotateRadian = rotateDeg * Math.PI / 180;
     const arrowWH = arrowSize + borderWidth;
     const rotatedWH = arrowWH * Math.abs(Math.cos(rotateRadian)) + arrowWH * 
Math.abs(Math.sin(rotateRadian));
     const arrowOffset = Math.round(((rotatedWH - Math.SQRT2 * borderWidth) / 2
         + Math.SQRT2 * borderWidth - (rotatedWH - arrowWH) / 2) * 100) / 100;
-    positionStyle += `;${arrowPos}:-${arrowOffset}px`;
+    arrowCSSStyle[arrowPos] = `-${arrowOffset}px`;
 
     const borderStyle = `${borderColor} solid ${borderWidth}px;`;
-    const styleCss = [
-        
`position:absolute;width:${arrowSize}px;height:${arrowSize}px;z-index:-1;`,
-        `${positionStyle};${transformStyle};`,
-        `border-bottom:${borderStyle}`,
-        `border-right:${borderStyle}`,
-        `background-color:${backgroundColor};`
-    ];
-
-    return `<div style="${styleCss.join('')}"></div>`;
+
+    arrowCSSStyle.position = 'absolute';
+    arrowCSSStyle.width = `${arrowSize}px;`;
+    arrowCSSStyle.height = `${arrowSize}px;`;

Review Comment:
   CSSOM property setters accept a value, not a declaration terminated by `;`. 
The trailing semicolons in `borderStyle`, `width`, and `height` make these 
assignments invalid, leaving the tooltip arrow without its intended size or 
borders. Remove the semicolons from all three values.



##########
src/data/SeriesData.ts:
##########
@@ -946,20 +971,13 @@ class SeriesData<
     }
 
     /**
-     * Select data in range. (For optimization of filter)
-     * (Manually inline code, support 5 million data filtering in data zoom.)
+     * @see DataStore['selectRange']
      */
-    selectRange(range: Record<string, [number, number]>): SeriesData {
-        'use strict';
-
+    selectRange(range: zrUtil.HashMap<[number, number], SeriesDimensionName>): 
SeriesData {
         const innerRange: Record<number, [number, number]> = {};
-        const dims = zrUtil.keys(range);
-        const dimIndices: number[] = [];
-        zrUtil.each(dims, (dim) => {
-            const dimIdx = this._getStoreDimIndex(dim);
-            innerRange[dimIdx] = range[dim];
-            dimIndices.push(dimIdx);
-        });
+        range.each(function (rangeItem, dimName) {

Review Comment:
   `SeriesData` is publicly exported as `echarts.List` 
(`src/export/api.ts:60`). Existing callers passing a dimension-to-range object, 
such as `list.selectRange({x: [0, 10]})`, now throw because plain objects have 
no `each` method. Keep accepting the existing object form alongside HashMap, or 
normalize it internally, so this safety refactor does not break extension 
callers.



##########
test/toolbox-textStyle.html:
##########
@@ -139,7 +139,12 @@
             document.head.appendChild(font1);
             document.head.appendChild(font2);
 
-            document.fonts.ready.then(function () {
+            // document.fonts.ready is not necessarily guarantee all fonts are 
loaded.
+            // Unused fonts might never be loaded. So use this way instead.
+            Promise.all([
+                document.fonts.load('400 16px "Noto Sans SC"'),
+                document.fonts.load('400 16px Courgette')
+            ]).then(function () {

Review Comment:
   The font stylesheets have only just been appended, so their `@font-face` 
rules may not be registered when `document.fonts.load()` runs. It can then 
resolve without loading those faces, creating the chart with fallback fonts and 
unstable screenshots. Wait for both stylesheet `load` events before requesting 
the fonts.



##########
src/util/decal.ts:
##########
@@ -297,7 +297,7 @@ export function createOrUpdatePatternFromDecal(
                 }
                 else {
                     // Paint to canvas for all other renderers.
-                    brushSingle(ctx, symbol);
+                    brushSingle(ctx, symbol, dpr);

Review Comment:
   Symbol coordinates and dimensions are already multiplied by `dpr` above, so 
passing it to `brushSingle` scales them again and enlarges or clips decals on 
high-DPI canvases. [ZRender's default-branch 
implementation](https://github.com/ecomfe/zrender/blob/24f08c7303dd474e0e6de7dab2ba8793684c3f1f/src/canvas/graphic.ts#L516-L524)
 applies that additional canvas transform. Pass `1` for these already-scaled 
symbols.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to