New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when 'Allow Hyphens in Short URLs' is disabled #2280

Open
atdr opened this Issue Aug 12, 2017 · 11 comments

Comments

Projects
None yet
6 participants
@atdr

atdr commented Aug 12, 2017

Reproducible bug summary

  1. enable Allow Hyphens in Short URLs plugin
  2. create short URL containing hyphen(s)
    e.g. sho.rt/a-b
  3. deactivate plugin;
    • hyphens not shown in Short URL column in admin/index.php
      i.e. sho.rt/ab shown where sho.rt/a-b used to be
    • neither sho.rt/a-b nor sho.rt/ab successfully redirect to target
    • trying to delete the link results in the error
      something wrong happened while deleting :/

Technical details

  • YOURLS version: 1.7.2
  • PHP version: 7.1.8
  • Ubuntu 16.04.3 LTS w/ Apache 2.4.27
@dgw

This comment has been minimized.

Show comment
Hide comment
@dgw

dgw Aug 12, 2017

Collaborator

You're surprised that deactivating the Allow Hyphens in Short URLs plugin breaks short URLs containing hyphens?

Collaborator

dgw commented Aug 12, 2017

You're surprised that deactivating the Allow Hyphens in Short URLs plugin breaks short URLs containing hyphens?

@atdr

This comment has been minimized.

Show comment
Hide comment
@atdr

atdr Aug 12, 2017

@dgw not surprised at all but thought that it might be confusing for other users 🤷‍♂️

atdr commented Aug 12, 2017

@dgw not surprised at all but thought that it might be confusing for other users 🤷‍♂️

@ozh

This comment has been minimized.

Show comment
Hide comment
@ozh

ozh Aug 12, 2017

Member

I agree there's something to be improved here: at least you should be able to delete such a link or do something with it. I'll look into things.

Member

ozh commented Aug 12, 2017

I agree there's something to be improved here: at least you should be able to delete such a link or do something with it. I'll look into things.

@Sushubh

This comment has been minimized.

Show comment
Hide comment
@Sushubh

Sushubh Sep 3, 2017

I have experimented with so many non-default characters, I am now wondering what I would do when a major new update is released!

Sushubh commented Sep 3, 2017

I have experimented with so many non-default characters, I am now wondering what I would do when a major new update is released!

@TuKod

This comment has been minimized.

Show comment
Hide comment
@TuKod

TuKod Oct 10, 2017

@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[0]; // -
echo $extra[1]; // ~
echo $extra[6]; // ^

You could then experiment by simply changing the config file.

Pop VeKind

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!

TuKod commented Oct 10, 2017

@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[0]; // -
echo $extra[1]; // ~
echo $extra[6]; // ^

You could then experiment by simply changing the config file.

Pop VeKind

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!

@Sushubh

This comment has been minimized.

Show comment
Hide comment
@Sushubh

Sushubh Oct 10, 2017

I am actually using this plugin:
http://github.com/josheby/yourls-additional-charsets

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

Sushubh commented Oct 10, 2017

I am actually using this plugin:
http://github.com/josheby/yourls-additional-charsets

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

@TuKod

This comment has been minimized.

Show comment
Hide comment
@TuKod

TuKod Oct 10, 2017

@ozh - Just a flash idea...

Perhaps leave the Admin basically the same with the added ability to delete any entry.
Likewise, when the shortened URL was serviced, maybe we should check anything against the DB.
For example, we add the keyword 123-XYZ to the Database. Then remove the hyphen plugin. 123-XYZ could be allowed to work IF it is already in the DB, just no new hyphen keys would be allowed to be added.

Just a thought.

TuKod commented Oct 10, 2017

@ozh - Just a flash idea...

Perhaps leave the Admin basically the same with the added ability to delete any entry.
Likewise, when the shortened URL was serviced, maybe we should check anything against the DB.
For example, we add the keyword 123-XYZ to the Database. Then remove the hyphen plugin. 123-XYZ could be allowed to work IF it is already in the DB, just no new hyphen keys would be allowed to be added.

Just a thought.

@TuKod

This comment has been minimized.

Show comment
Hide comment
@TuKod

TuKod Oct 10, 2017

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

Pop VeKind

TuKod commented Oct 10, 2017

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

Pop VeKind

@PopVeKind

This comment has been minimized.

Show comment
Hide comment
@PopVeKind

PopVeKind Dec 22, 2017

Contributor

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
Something-Special! Then changed to a strict 36 only, your keyword Something-Special! would continue to work.

If it is in the DB and you don't want it, just delete it.

Automatic Only

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!

Contributor

PopVeKind commented Dec 22, 2017

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
Something-Special! Then changed to a strict 36 only, your keyword Something-Special! would continue to work.

If it is in the DB and you don't want it, just delete it.

Automatic Only

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!

@ozh

This comment has been minimized.

Show comment
Hide comment
@ozh

ozh Dec 22, 2017

Member

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

Member

ozh commented Dec 22, 2017

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

@PopVeKind

This comment has been minimized.

Show comment
Hide comment
@PopVeKind

PopVeKind Apr 24, 2018

Contributor

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 somefile.php or robots.txt

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.

Contributor

PopVeKind commented Apr 24, 2018

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 somefile.php or robots.txt

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.

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