superseriousbusiness / gotosocial

Fast, fun, small ActivityPub server.
https://docs.gotosocial.org
GNU Affero General Public License v3.0
3.85k stars 339 forks source link

[bug] sending empty expires_in to filter v2 endpoints sets expiration to now #3497

Closed connyduck closed 1 day ago

connyduck commented 4 weeks ago

Describe the bug with a clear and concise description of what the bug is.

When creating or editing a filter v2, it is not possible to set the duration to indefinite.

What's your GoToSocial Version?

0.17.2-SNAPSHOT+git-1954ccb

GoToSocial Arch

goblin.technology

What happened?

I created a Filter like this:

POST https://goblin.technology/api/v2/filters
Content-Type: application/x-www-form-urlencoded
Content-Length: 63
Authorization: Bearer <>
User-Agent: Tusky/26.2-7008c48a Android/13 OkHttp/4.12.0
title=test123&context%5B%5D=home&filter_action=warn&expires_in=

I got the following response:

{
    "id": "01JBCS3BBG8QJAEQ2XCYTACXPC",
    "title": "test123",
    "context": [
        "home"
    ],
    "expires_at": "2024-10-29T18:37:35.984Z",
    "filter_action": "warn",
    "keywords": [],
    "statuses": []
}

As you can see, it has the expiration set to now. The same happens when editing the filter with PUT /api/v2/filters

What you expected to happen?

As per api docs and Mastodon behavior, I would expect the expiration to be indefinite.

How to reproduce it?

Create or edit a filter.

Anything else we need to know?

No response

tsmethurst commented 4 weeks ago

Ah thanks!

connyduck commented 2 weeks ago

While this works now when creating a filter, it seems the expires_at parameter is ignored when updating one.

tsmethurst commented 2 weeks ago

Oh bollocks is it? I'll take another look, thanks.

connyduck commented 1 week ago

To be precise, when setting expires_at to a value it works fine, but setting it to empty still does not set the expiration to indefinite. (goblin.technology 0.17.4-SNAPSHOT+git-b846378)

VyrCossont commented 1 week ago

Oh, I think I know what causes this, but we may have to do some custom form deserialization to work around it.

VyrCossont commented 4 days ago

There's also a JSON equivalent of this bug: sending a literal null for expires_in should unset the expiration date (and does on Mastodon), but does not, yet. #3560 should match Mastodon behavior for both empty strings in the form version of the API, and empty strings or nulls in the JSON version.