Open irfaan opened 7 years ago
Happened to see the same issue today. As a quick fix I'm going to use ~
instead of -
in the set of characters and hope it doesn't cause any problem :)
Edit Looks like some android devices drop the tilde, too. Agh!
@tsriram Great idea. Will do the same. Thank you!
Section 2.3 of RFC 3986 confirms that ~
is url safe.
@irfaan yeah, some (if not all) of Android devices drop tilde too. I'm currently doing a brute force way of generating shortid repeatedly till I get one that doesn't end with a special character. Not at all the best way but I was running out of time to dig into it. And can't have broken URLs sent to users!
var shortid = require('shortid')
var shortidNotEndWithSpecialCharacter = function () {
var id
do {
id = shortid.generate();
}
while(id[0] === '-' || id[0] === '_' || id.slice(-1) === '-' || id.slice(-1) === '_');
return id;
}
Removing IDS with last -
is bad for uniformity. It is better to do shortid.generate().replace(/-/g, '~')
or use nanoid
We saw the same issue with _
, $
and @
.
Change alphabet by:
shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~_')
Or use Nano ID which use ~
instead of -
.
@ai happens with tilde (~), too: https://github.com/dylang/shortid/issues/96#issuecomment-306293440
Just a PSA - I have noticed that, when texting a url with a trailing dash, some android devices are dropping the trailing dash when parsing urls in text messages. It seems to only happen when text follows a url with a trailing dash.