Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Errors when 'Allow Hyphens in Short URLs' is disabled #2280
Reproducible bug summary
@Sushubh - Wouldn't it be better to make a copy of the Allow Hyphens in Short URLs plugin? Then adjust it to make your own plugin for your "many non-default characters." In your config file add a Constant with a list of "non-default characters." separated by a specified standard character from the 36 base. For example, using the number "8" as a separator:
define( 'NON_DEFAULT_CHARACTERS', '-8~8!8@8#8$8%8^8&8*8(8)8_8+' );
Note: I am not saying any of those "non-default characters" would actually work!
Then, within a function in your plugin, you can explode these into an array.
$extra = explode( "8", NON_DEFAULT_CHARACTERS );
$extra would then be a nice array of all your "non-default characters" you could use in your plugin.
echo $extra; // -
You could then experiment by simply changing the config file.
PS: Did you consider the value of the extra characters?
Are you running a goo.gl or bit.ly where these may be important? If you are you will likely need more resources an more knowledge to make it work.
Are you running a private YOURLS? Likely the defaults are plenty.
Do you just want to see if it can be done? Will it work? Then you are near and dear to my heart. Good luck, it is the journey that matters. Make the above suggested any extra characters plugin and enjoy!
I am actually using this plugin:
I was more concerned about a major update that would break compatibility with older plugins (something i am soon going to experience with xenforo2 release)!
@ozh - Just a flash idea...
Perhaps leave the Admin basically the same with the added ability to delete any entry.
Just a thought.
@Sushubh - Ah yes, that is always a problem. How to "Future Proof" a program/plugin? It cant be done.
yourls-additional-charsets looks good though. I especially like that you can supply your own Custom Charset. Actually, I like simple things and that is all I would use.
I would not worry about this breaking in future releases of YOURLS. It uses a standard hook - 'get_shorturl_charset' - which appears to be designed in the core files for just this sort of purpose.
An Evolving Idea...
I've been chewing on this problem for a while. I'm working on a Settings Page to replace the constants in the config file. It is basically the same as, "What if I change my settings from 62 to 36?" (uppercase, lowercase, and numbers, to only lowercase and numbers?) It also fails on the uppercase letters.
I believe setting changes should not cause failures.
DB Entries Are Legal
The solution is simple, make all entries in the DB legal. This would mean setting changes would not break anything. If you had settings of 62, plus hyphens, plus exclamation points and a keyword
If it is in the DB and you don't want it, just delete it.
Use the restriction settings only in the making of short URLs during automatic mode.
Allow Manual Override
When adding or editing a short URL MANUALLY, you should have the power of adding characters outside of the restricted range prescribed in settings for automatic URLs. Perhaps with a warning!
@PopVeKind your 1200 word comment is equal to what I said earlier here and in other issues: one should be able to modify a link from a different charset, and link created with a once valid charset should remain valid. At this point, what we need is a PR, not opinions.
I am looking at how to make a PR for this problem. I wondered if other characters may be involved?
To quote section 2.3 of RFC 3986: (http://www.ietf.org/rfc/rfc3986.txt) "Characters that are allowed in a URI but do not have a reserved purpose are called unreserved. These include uppercase(A-Z), lowercase(a-z), decimal digits(0-9), hyphen(-), period(.), underscore(_), and tilde(~)."
Periods(.) may be problematic in some advanced YOURLS as they could be confused with file names like
There is a plugin that allows the use of the slash (/). This is not even an unreserved character and does conflict with other plugins or colocated programs.
For redirection, I can see no reason why uppercase (A-Z) lowercase (a-z), decimal digits (0-9), hyphen (-), underscore (_) and tilde (~) could not just be passed to the DB and allowed to pass or fail based on being in the DB.
Anyone deciding to use a period (.) or slash (/) or any other character, should be advised to do so at their own risk as these are advanced options that may conflict with other plugins or programs.
What non-standard (a-z, A-Z, 0-9) characters do you use?
This should solve the 'Allow Hyphens in Short URLs' problem.