String.prototype.match with a global RegExp returns [] instead of null when nothing matches
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c, javascript
- Domain
- backend
Research direction
Start by reading njs_string_match_multiple() in the njs source and trace where it assigns the result after the match loop. Reproduce the issue with the provided script using ./build/njs; the expected output is null for all three cases. Check the project’s relevant tests and add coverage for global expressions with no matches; done means those cases return null while existing match behavior still passes.
Written by the indexing model from the issue text.
Description
Describe the bug
String.prototype.match(re) with a global regular expression returns [] instead of null when nothing matches.
- The bug is reproducible with the latest version of njs.
- I minimized the code and NGINX configuration to the smallest possible to reproduce the issue.
To reproduce
Steps to reproduce the behavior:
- JS script
console.log(JSON.stringify("abc".match(/x/g)));
console.log(JSON.stringify("abc".match(/(x)/gi)));
console.log(JSON.stringify("abc".match(/x/)));
- Exact steps to reproduce the behavior
Run ./build/njs on the script above. It prints:
[]
[]
null
Expected behavior
All three cases should evaluate to null and print:
null
null
null
Your environment
- Version of njs or specific commit: 1.0.3
- Version of NGINX if applicable: N/A (standalone njs CLI)
- List of other enabled nginx modules if applicable: N/A
- OS: Linux
Additional context
njs_string_match_multiple() initializes retval to null, but sets retval to the match array after the match loop even when array->length == 0.
Credit: https://ucsbplse.github.io/
- Dominant language
- C
- Stars
- 1.6k
- Forks
- 245
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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 nginx/njs
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Modules: CR/LF in njs-produced nginx variablesMay be free again @xeioex claimed this 47 days ago, and no pull request is open. Opennjs
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Potential memory leak in njs_fs_fd_read error pathsPossibly taken @Shubham-Padkonde claimed this 42 days ago. Opennjs
Difficulty 3/5 1-2 days Newbie friendliness 67/100
-
feature njs
Difficulty 5/5 Over a week Newbie friendliness 30/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
-
bug mod: circuit
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
msys2/MINGW-packages#33356 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
facebookincubator/muse-gadget-sdk#355 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
kmod-project/kmod#492 ·
Maintainers usually reply within 4 days