Skip to content

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

Description

@SantoshMettu

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions