Skip to content

fix(dataset): exclude missing values from regexp filters - #21828

Open
WhyTan00 wants to merge 1 commit into
apache:masterfrom
WhyTan00:fix/filter-regexp-missing-values-20261108
Open

WhyTan00 wants to merge 1 commit into
apache:masterfrom
WhyTan00:fix/filter-regexp-missing-values-20261108

Conversation

@WhyTan00

@WhyTan00 WhyTan00 commented Nov 8, 2026

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Keep missing dataset values from matching regular expression filters as the literal strings "null" or "undefined".

Fixed issues

No existing issue was found in the targeted search. The reproduction is included below.

Details

Before: What was the problem?

RegExpEvaluator.evaluate passes the result of typeof lVal to isString and isNumber. Since every typeof result is itself a string, the string branch always runs. RegExp.test then coerces missing values to strings instead of reaching the existing non-string/non-number false branch.

For example, use this normal dataset filter:

const source = [
    { id: 'missing-null', value: null },
    { id: 'missing-undefined', value: undefined },
    { id: 'missing-property' },
    { id: 'literal-null', value: 'null' },
    { id: 'literal-undefined', value: 'undefined' },
    { id: 'number', value: 42 },
    { id: 'numeric-string', value: '42' }
];
const dataset = [
    { dimensions: ['id', 'value'], source },
    { transform: { type: 'filter', config: { dimension: 'value', reg: '^null$' } } }
];

Before this fix, ^null$ selects both missing-null and literal-null. Replacing the condition with ^undefined$ selects missing-undefined, missing-property, and literal-undefined. The same happens with RegExp objects instead of string conditions. null/undefined are supported OptionDataValue values; absent properties in object rows also yield undefined through the normal source provider.

After: How does it behave after the fixing?

Check the original value with isString(lVal) / isNumber(lVal) so the existing type guard works as intended. The two filters select only their corresponding literal strings. Numbers still match their string representation: ^42$ selects both number and numeric-string.

The change is limited to the guard. No comparator API, transform registration, or global/sticky regular expression lastIndex policy is changed.

Document Info

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

Added 10 regressions through the real createSource / applyDataTransform / built-in filter path, covering array rows, object rows, missing vs literal values, both supported regexp condition forms, valid numeric matches, and logical/piped filters. No comparator or classifier is mocked.

On the unchanged base, 6 of the new tests fail and 4 pass. With the fix, all 10 new tests and the 8 existing data-transform tests pass:

./node_modules/.bin/jest --config test/ut/jest.config.cjs --runInBand --coverage=false --runTestsByPath test/ut/spec/data/filterTransform.test.ts test/ut/spec/data/dataTransform.test.ts
./node_modules/.bin/eslint src/util/conditionalExpression.ts
git diff --check

The direct CLI source-module reproduction also confirms the before/after filtered rows. No browser or visual rendering is claimed; this is a data-filtering change, and the existing Jest data-transform suite uses jsdom/canvas mocks.

Local environment: Node 24.22.1, TypeScript 4.4.3, Jest 26.6.3, zrender 6.1.0. The canonical root and bmap typecheck commands were attempted but are blocked by 1,364 parse errors in the installed @types/node and @types/babel__traverse declarations. They are not reported as passing; no dependency or TypeScript configuration changes are included.

Merging options

  • Please squash the commits into a single one when merging.

Other information

OpenAI Codex assisted with the unchanged-source reproduction, narrow guard change, regression tests, and verification described above.

@echarts-bot

echarts-bot Bot commented Nov 8, 2026

Copy link
Copy Markdown

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant