Is it possible to add @ as a supported character? #2155

Open
adigitalife opened this Issue Oct 5, 2016 · 5 comments

Projects

None yet

4 participants

@adigitalife
Contributor

Some users want to use hyphens in their short URLs so I created a plugin to add it. Now, some users want @ in their short URLs. But adding it to the charset breaks YOURLS. Short links can be create with @ in them but none of the short links work anymore (with or with @).

What's preventing @ from working?

@ozh
Member
ozh commented Oct 5, 2016

Probably an encoding issue, maybe somewhere the @ becomes a %40. Check how short URLs are stored (with a @ ?) and what YOURLS receives when requested a short URL, see https://github.com/YOURLS/YOURLS/blob/master/yourls-loader.php#L20-L21

@adigitalife
Contributor

Actually, simply adding @ to the charset already breaks the site. No need to create any short links. Here's how I reproduce the issue:

  1. Add @ to function yourls_get_shorturl_charset() in includes/functions.php

if( defined('YOURLS_URL_CONVERT') && in_array( YOURLS_URL_CONVERT, array( 62, 64 ) ) ) { $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@';

  1. Try any existing short link. Doesn't work. Simply goes to the YOURLS home page.

  2. Remove @ from function yourls_get_shorturl_charset(), site goes back to normal.

Other special characters are fine:

$charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!-_.?#$';

But as soon as I add @, all short links stop working.

@mdbuerkle

As far as I remember, changing the charset also invalidates all short links that have been created until then - so "2) try an existing short link" will never work.
Anyhow, when chaning charset, You also have to change YOURLS_URL_CONVERT accordingly, i.e. it would be "63" with the "@" in Your case.
Did You try to add a new short link with the "@" in Your charset, then?

@adigitalife
Contributor

But why does 2) work if I use other special characters in 1)? So...

  1. Add one or more special characters (except @) to function yourls_get_shorturl_charset() in includes/functions.php

if( defined('YOURLS_URL_CONVERT') && in_array( YOURLS_URL_CONVERT, array( 62, 64 ) ) ) { $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!-_.?#$';

  1. Try any existing short link. They all work.

  2. Create new short links with the added special characters. They all still work.

But, as I said, once @ is added none of the short links work anymore. So at least in my case, the only problem is really with @.

I'll try changing 62 to 63 when I can. It may or may not work. But the question still remains: Why does @ behave different than the other special characters?

@slabbint

I would also like to add the @ character to the list of supported characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment