Codeinwp / tweet-old-post

Plugin to tweet about your old posts to get more hits for them and keep them alive.
GNU General Public License v2.0
13 stars 16 forks source link

Fix `is.gd` url shorted response handling #904

Closed Soare-Robert-Daniel closed 6 months ago

Soare-Robert-Daniel commented 7 months ago

Close https://github.com/Codeinwp/tweet-old-post-pro/issues/480

Summary

Added better service response handling and upgraded the URL to use the latest API endpoint.

Description

The posting mechanism added a message like that ends Error, database insert failed. This was caused by the function get_url, which tries to shorten the URL by using is.gd service.

To replicate this issue you need a valid domain. The services work only with URLs that are available on the internet and are not on the blocklist (FYI: tastewp URLs are on the blacklist).

The main problem is that when services cannot process the URL, it will give something like this as a response:

HTTP/1.1 200 OK
CF-Cache-Status: DYNAMIC
CF-RAY: 8498b6a71ad9c29b-VIE
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Mon, 22 Jan 2024 15:08:39 GMT
Server: cloudflare
Set-Cookie: __cf_bm=mW5ZRykpgHu1OaXthztTO_deplxvZmh1GJQQh5ZjYe4-1705936119-1-Ac1gBGUi4m8U+2XoNRIPkBDKqlflPfMpNyDzVnOqUUboQiG9+WsZOp8/Iv56lF01CuOq1UdT0QkG9pzUkVA7fvQ=; path=/; expires=Mon, 22-Jan-24 15:38:39 GMT; domain=.is.gd; HttpOnly; Secure; SameSite=None
Transfer-Encoding: chunked

Error, database insert failed

Because the response error is 200, the code accepted the string without further verification.

To solve this, I added a check to see that the response is a URL.

Any other response from the server will be treated as an error and logged:

image

There was also a report about the same issue for people who did not use the URL shortener https://github.com/Codeinwp/tweet-old-post-pro/issues/480#issuecomment-1896311145

I tested all the codes and could not reproduce them.

Testing

github-actions[bot] commented 7 months ago

Plugin build for aba40761ee41a595b223b5cab52fd933cd799b4f is ready :bellhop_bell:!

irinelenache commented 7 months ago

@Soare-Robert-Daniel Tested and the issue is fixed now 🚀

pirate-bot commented 6 months ago

:tada: This PR is included in version 9.0.23 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: