Skip to content

Fix substring selectors (*=, ^=, $=) throwing on numeric values - #3547

Merged
maxkfranz merged 1 commit into
cytoscape:masterfrom
Enesuygurs:fix/selector-string-ops-numeric-values
Oct 27, 2026
Merged

maxkfranz merged 1 commit into
cytoscape:masterfrom
Enesuygurs:fix/selector-string-ops-numeric-values

Conversation

@Enesuygurs

@Enesuygurs Enesuygurs commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Cross-references to related issues. If there is no existing issue that describes your bug or feature request, then create an issue before making your pull request.

Associated issues:

Notes re. the content of the pull request. Give context to reviewers or serve as a general record of the changes made. Add a screenshot or video to demonstrate your new feature, if possible.

  • cy.$('[weight ^= 1]') throws TypeError: Cannot read properties of undefined (reading 'indexOf') when any element's weight is a number, a boolean or missing. The same goes for *= and $= with a number value, including in stylesheet selectors.
  • In valCmp() (src/selector/data.mjs), the string forms of the field and value were only built when one of them was a string or the comparison was case-insensitive. The substring operators always need those strings, so comparing a number with a number called undefined.indexOf().
  • This PR always builds the string forms for *=, ^= and $=, including their ! and @ variants. That matches what [weight @^= 1] already did. =, !=, <, > and the other operators are unchanged.
  • Added selector tests for *=, ^=, $= and !*= with numeric values, plus one with a non-string field. They fail with the TypeError before the fix and pass after it. npm run test:js gives 764 passing and npm run test:modules gives 46 passing.

Checklist

Author:

  • The proper base branch has been selected. New features go on unstable. Bug-fix patches can go on either unstable or master.
  • Automated tests have been included in this pull request, if possible, for the new feature(s) or bug fix. Check this box if tests are not pragmatically possible (e.g. rendering features could include screenshots or videos instead of automated tests).
  • The associated GitHub issues are included (above).
  • Notes have been included (above).
  • For new or updated API, the index.d.ts Typescript definition file has been appropriately updated. (No API change.)

Reviewers:

  • All automated checks are passing (green check next to latest commit).
  • At least one reviewer has signed off on the pull request.
  • For bug fixes: Just after this pull request is merged, it should be applied to both the master branch and the unstable branch. Normally, this just requires cherry-picking the corresponding merge commit from master to unstable -- or vice versa.

Summary by CodeRabbit

  • Bug Fixes

    • Numeric values can now be matched with substring, prefix, and suffix selectors by comparing their string representations. Negated substring selectors are also covered by this behavior.
  • Tests

    • Added coverage for numeric substring selectors and for queries that should not match any elements.

`[name *= value]`, `[name ^= value]` and `[name $= value]` threw a TypeError
when the value was a number and the data field was not a string (e.g. a
numeric, boolean or missing field), because the string forms of the field
and value were never computed. Always compare string representations for
the substring operators, as the case-insensitive variants already do.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: 38514c5b-859e-42f9-a9b2-09d2db3c5962
📥 Commits

Reviewing files that changed from the base of the PR and between e394aa8 and 52417db.

📒 Files selected for processing: 2
  • src/selector/data.mjs
  • test/selectors.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

valCmp now initializes string representations for substring operators when comparing numeric operands. Selector tests cover numeric substring, prefix, and suffix comparisons, negation, and a query with no expected matches.

Changes: Selector comparisons

Layer / File(s) Summary
String representation for substring comparisons
src/selector/data.mjs, test/selectors.mjs
valCmp initializes string representations for substring operators. Tests cover numeric *=, ^=, and $= comparisons, negated substring matching, and a query with no expected matches.

Priority: Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

  • Issue 3546 describes failures in substring comparisons with numeric, boolean, or missing fields. This change computes string representations for substring operators, addressing the numeric comparison case.
Merge Risk: Minimal · up to 52417

No actionable merge-blocking risk is identified in this selector change.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing substring selectors from throwing errors for numeric values.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@maxkfranz
maxkfranz self-requested a review October 27, 2026 15:02
@maxkfranz
maxkfranz merged commit 51aaaef into cytoscape:master Oct 27, 2026
2 checks passed
@maxkfranz

Copy link
Copy Markdown
Member

Very good. Thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Substring selectors (*=, ^=, $=) throw a TypeError when the value is a number and the field is not a string

2 participants