date_time, url_encode, html_escape, to_unix_time, contains_all and contains_any panic when called without arguments
Maintainers usually reply within 1 day
A pull request for this has already been merged.
- #373 by @antcybersec — merged
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start with the date_time helper, where the argument-count check runs after arguments[0] is read and uses && where it needs ||. The other five helpers (url_encode, html_escape, to_unix_time, contains_all, contains_any) lack any count check and should return ErrInvalidDslFunction for zero arguments. Done means all six return that error with no arguments, date_time rejects extra arguments, and TestHelpersDoNotPanicOnNumericArgument also covers zero-argument calls.
Written by the indexing model from the issue text.
Description
Description
Six variadic helpers read args[0] before checking how many arguments they got. govaluate doesn't check argument counts when an expression is compiled, so a template with this mistake passes validation and then panics at run time. On main @ d61d88b:
date_time() => panic: runtime error: index out of range [0] with length 0
url_encode() => panic: runtime error: index out of range [0] with length 0
html_escape() => panic: runtime error: index out of range [0] with length 0
to_unix_time() => panic: runtime error: index out of range [0] with length 0
contains_all() => panic: runtime error: index out of range [0] with length 0
contains_any() => panic: runtime error: index out of range [0] with length 0
The aliases without underscores behave the same.
date_time also accepts too many arguments: date_time("%Y", 0, 1) ignores the timestamp and returns the current year (2026), where it should return an error.
Root cause
date_timechecksif argumentsSize < 1 && argumentsSize > 2, which can never be true; it should use||. The check also runs aftertoString(arguments[0]), so it would come too late anyway.url_encode,html_escape,to_unix_time,contains_allandcontains_anyhave no argument-count check.
This is the same class of bug as #357 and #367. TestHelpersDoNotPanicOnNumericArgument calls each helper with 1 to 4 arguments but never with 0, which is why these were missed.
Fix
- In
date_time, change&&to||and move the check above the firstarguments[0]read. - In the other five, return
ErrInvalidDslFunctionwhenlen(args) < 1. - Extend the no-panic test to call each helper with zero arguments as well.
I can send a PR for this.
- Dominant language
- Go
- Stars
- 125
- Forks
- 36
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 10
Getting set up
- No Dockerfile or Docker Compose file
- No 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.
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
agent-butler-finding chore
Difficulty 1/5 Under an hour Newbie friendliness 78/100
jordansmall/spindrift#6318 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Eyevinn/moqlivemock#166 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JakeChampion/lang#14091 ·
Maintainers usually reply within 1 day
-
batcher: BAF send context leaks per batchPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
hyperledger/fabric-x-orderer#1409 ·
Maintainers usually reply within 3 days