hash_obj_*()/hash_raw_*() variants don't validate parameter bounds, unlike their base hash_*() counterparts (affects animal and emoji hashes)

Open Beginner friendly
#834 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
r
Domain
cli

Research direction

Start in R/hash.R with hash_animal(), hash_raw_animal(), hash_emoji(), and hash_raw_emoji(), comparing the parameter checks in the base functions with their raw variants; the object variants call the raw functions. Confirm the documented bounds and make the behavior consistent across each function family, then verify invalid n_adj and size values are handled consistently.

Written by the indexing model from the issue text.

Description

bug

For both the adjective-animal hash and the emoji hash families, the "base" function validates its size-related parameter, but the raw and obj variants do not — despite sharing the same documented constraints.

1. hash_animal() family — n_adj (documented: "must be from 0 through 3")

r
cli::hash_animal("test", n_adj = 9)
#> Error: n_adj >= 0 && n_adj <= 3 is not TRUE

cli::hash_obj_animal("test", n_adj = 9)
#> runs without error

cli::hash_raw_animal(as.raw(1:4), n_adj = 9)
#> runs without error

2. hash_emoji() family — size (documented: "currently it has to be from 1 through 4")

r
cli::hash_emoji("test", size = 9)
#> Error: size >= 1 && size <= 4 is not TRUE

cli::hash_obj_emoji("test", size = 9)
#> runs without error

cli::hash_raw_emoji(as.raw(1:4), size = 9)
#> runs without error

Question / request

Please confirm if the documented note (that these parameters "must be" within the stated range) is correct and the code needs a fix to enforce it consistently — or if the intended behavior is looser than documented and the documentation needs an update instead.

Where this comes from

In R/hash.R:

hash_animal() has a stopifnot() checking n_adj; hash_raw_animal() (and by extension hash_obj_animal(), which calls it) only checks is.raw(x).
hash_emoji() has a stopifnot() checking size; hash_raw_emoji() (and by extension hash_obj_emoji()) only checks is.raw(x).

Dominant language
R
Stars
726
Forks
94
Avg merge
3h 35m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/cli

All issues in r-lib/cli

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.