[p5.js 2.0+ Bug Report]: splitTokens() returns [] for a caret delimiter and throws for a backslash
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript
- Domain
- frontend
Research direction
Start at the splitTokens implementation and its existing unit tests. Reproduce the caret and backslash cases, then check coverage for bracket, array-delimiter, and whitespace behavior. Done means literal special-character delimiters produce the expected tokens without breaking the existing cases.
Written by the indexing model from the issue text.
Description
Most appropriate sub-area of p5.js?
Utilities
p5.js version
2.x main (4b096e2)
Actual vs expected behavior
splitTokens builds a regex character class from the delimiter characters with only [ and ] special-cased (the 2015 fix for #1004), so other regex metacharacters corrupt the class:
splitTokens('a^b', '^'); // actual [] expected ['a', 'b']
// the ^ negates the class, so every character becomes a delimiter
splitTokens('a\b', '\'); // actual SyntaxError: Invalid regular expression: /[\]/g
// expected ['a', 'b']
A - between delimiter characters also silently forms a range instead of matching the literal characters.
Steps to reproduce
Outputs above are from executed runs against current main.
Note
I am aware splitTokens was deprecated in 2.0 (#7624), so feel free to close this as wontfix if the function is not receiving fixes anymore. If it is, I have a small fix ready (escape \, ], ^, - when building the class) with unit tests for both broken cases plus regression coverage for the existing bracket, array-delimiter and whitespace behaviors; the two new tests fail on current main and pass with the change. Will open the PR once approved.
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 26
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from processing/p5.js
-
Area:Math p5.js 2.0+
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
processing/p5.js#9197 · 3 comments · 1 assignee ·
-
Area:Core Area:DOM
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
processing/p5.js#9189 ·
-
[Bug]: p5.Image.prototype.copy and blend do not scale destination coordinates for high pixel density Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
processing/p5.js#9169 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
processing/p5.js#9129 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
processing/p5.js#9125 · 1 comment ·
All issues in processing/p5.js
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·