mkaczanowski / pastebin

Simple, fast, standalone pastebin service
MIT License
155 stars 27 forks source link

[Feature Request] URL slug should be alphanumeric/flexible #6

Closed acherunilam closed 3 years ago

acherunilam commented 3 years ago

By default, nanoid uses alphanumeric + underscore + minus. It does natively support specifying a custom character set, thankfully.

I prefer alphanumeric slugs so that it's way easier to recite the URL to others. Thoughts?

I guess you can make it more flexible and pick up the character set as a CLI arg, e.g. --slug-charset <char_set> Character set to use for generating the URL slug [default: A-Za-z0-9_-]. Your call.

mkaczanowski commented 3 years ago

yup, I agree the alphanumeric slugs are way better.

I'll add that option soon

acherunilam commented 3 years ago

@mkaczanowski It's not obvious that the charset is expected to be compatible with Rust's regex library. Can we make that clearer in the documentation?

Additionally, if a user mistakenly specifies a "wrong" regex, the server still starts up, only to get stuck with the first POST request it gets. Can we change this behavior to throw an error and not start in the first place?

$ cargo build

# user forgets to enclose the regex in brackets
# whoops, app starts and gets stuck after getting the first request instead of failing up front
$ ./target/debug/pastebin --slug-charset=a-z
...
🚀 Rocket has launched from http://localhost:8000
$ echo "hello World $RANDOM" | curl -q -L -d @- -o - http://localhost:8000/
# both server and client are stuck doing the POST request
mkaczanowski commented 3 years ago

It's not obvious that the charset is expected to be compatible with Rust's regex library. Can we make that clearer in the documentation?

Yup

Additionally, if a user mistakenly specifies a "wrong" regex, the server still starts up, only to get stuck with the first POST request

ugh, that's unexpected behavior. I'll fix that, though I am curious why it gets stuck... I'd rather expect some error/panic