dylang / shortid

Short id generator. Url-friendly. Non-predictable. Cluster-compatible.
https://www.npmjs.org/package/shortid
Other
5.74k stars 258 forks source link

Trailing dash in urls being dropped in sms - some android devices #96

Open irfaan opened 7 years ago

irfaan commented 7 years ago

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.

screen shot 2017-05-11 at 12 04 44 pm

tsriram commented 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 :)

irfaan commented 7 years ago

Edit Looks like some android devices drop the tilde, too. Agh! screen shot 2017-06-05 at 2 47 57 pm

@tsriram Great idea. Will do the same. Thank you! Section 2.3 of RFC 3986 confirms that ~ is url safe.

tsriram commented 7 years ago

@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!

giiska commented 7 years ago
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;
}
ai commented 7 years ago

Removing IDS with last - is bad for uniformity. It is better to do shortid.generate().replace(/-/g, '~') or use nanoid

asoesilo commented 6 years ago

We saw the same issue with _, $ and @.

ai commented 6 years ago

Change alphabet by:

shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~_')

Or use Nano ID which use ~ instead of -.

irfaan commented 6 years ago

@ai happens with tilde (~), too: https://github.com/dylang/shortid/issues/96#issuecomment-306293440