mrdimidium / nanoid

A tiny, secure, URL-friendly, unique string ID generator for Rust
https://docs.rs/nanoid
MIT License
545 stars 29 forks source link

Documentation is inconsistent with regards to the default alphabet. #33

Closed JordanRickman closed 1 year ago

JordanRickman commented 2 years ago

The documentation at https://docs.rs/nanoid/latest/nanoid/ claims that the default alphabet is A-Za-z0-9_~. This is stated several times in the text, and there is a code example which claims it may generate a string with a tilde:

If you want to reduce ID length (and increase collisions probability), you can pass the length as an argument generate function:

use nanoid::nanoid;

fn main() {
   let id = nanoid!(10); //=> "IRFa~VaY2b"
}

However, tilde (~) is not URL-safe.

nanoid::alphabet::SAFE, which the documentation claims is the default alphabet, contains the hyphen in place of the tilde. Presumably this is correct, and the documentation text is wrong.

jonjensen commented 1 year ago

Even with the change to - in the example, there is an inconsistency in the README.md documentation, which says:

The main module uses URL-friendly symbols (A-Za-z0-9_-) and returns an ID with 21 characters.

use nanoid::nanoid;

fn main() {
   let id = nanoid!(); //=> "Yo1Tr9F3iF-LFHX9i9GvA"
}

But then below that it says:

Symbols -,.() are not encoded in the URL. If used at the end of a link they could be identified as a punctuation symbol.

So it says - isn't being used, but above it shows that - is used.