vitorccs / yourls-api-save-by-keyword

YOURLS plugin which updates the long URL of an existing keyword, or creates a new short URL with the supplied keyword
GNU General Public License v3.0
0 stars 1 forks source link

Keywords are not normalized before use #1

Open axeld opened 1 year ago

axeld commented 1 year ago

If I use a keyword that contains invalid characters, "shorturl" filters them out automatically. For instance, if I use the keyword "new!", it will create the shortlink under the name "new".

When I do that with "save_by_keyword", it will just forward "new!" to "shorturl" AFAICT, and this will create the link "new". However, when I try to update an URL, "save_by_keyword" will fail to detect that "new" already exists, and will also forward "new!" to "shorturl", which will then fail.

axeld commented 1 year ago

I have opened a pull request with a fix for this issue: https://github.com/vitorccs/yourls-api-save-by-keyword/pull/3

vitorccs commented 1 year ago

Hi @axeld, thanks for reporting the issue and for your contribution

I made a couple of tests with your proposed correction, but it seems the problem still persists.

$keyword = yourls_apply_filter('custom_keyword', $keyword, $url, $title);

Added new URL (with keyword "test-1") OK = created as expected image

Updating existing URL (with keyword "test-1!") Failed = The long URL has not been updated image

vitorccs commented 1 year ago

@axeld by checking Yourls source code I could found the right way to sanitize keywords:

https://github.com/YOURLS/YOURLS/blob/02eda602ba2590519eb59020e0e7300cb08b1e72/includes/functions-shorturls.php#LL326C16-L326C39

$keyword = yourls_sanitize_keyword($keyword);

Updating existing URL (with keyword "test-1!") Success = Keyword was normalized + the long URL has been updated image

vitorccs commented 1 year ago

@axeld Please check the PR below and confirm if the problem is solved

PR https://github.com/vitorccs/yourls-api-save-by-keyword/pull/5