Skip to content

enh: validate datetime fields - #8388

Merged
luka-nextcloud merged 8 commits into
mainfrom
enhance-datetime-handling
Nov 25, 2026
Merged

luka-nextcloud merged 8 commits into
mainfrom
enhance-datetime-handling

Conversation

@luka-nextcloud

@luka-nextcloud luka-nextcloud commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Improve validation for date fields in card creation and update operations, ensuring that dates are properly formatted and do not exceed the year 9999.
  • Also enhance datetime fields handling on frontend to prevent invalid date selections.

Checklist

  • Code is properly formatted
  • Sign-off message is added to all commits
  • Tests (unit, integration, api and/or acceptance) are included
  • Documentation (manuals or wiki) has been updated or is not required

@github-project-automation github-project-automation Bot moved this to 🧭 Planning evaluation (don't pick) in 📝 Productivity team Sep 15, 2026
@luka-nextcloud luka-nextcloud moved this from 🧭 Planning evaluation (don't pick) to 👀 In review in 📝 Productivity team Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🐢 Performance warning.
It looks like the query count of the integration tests increased with this PR.
Database query count is now 204658 was 198420 (+3.14%)
Please check your code again. If you added a new test this can be expected and the base value in tests/integration/base-query-count.txt can be increased.

@blizzz blizzz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already stored values are not repaired, right? One-time repair job could be considered, or command. But I guess it is an edge case, though would be nice for affected users/admins to get out of it?

Comment thread lib/Validators/BaseValidator.php Resolved
Comment thread src/components/card/DueDateSelector.vue Resolved
Comment thread lib/Service/CardService.php Resolved
@github-actions

Copy link
Copy Markdown
Contributor

🐢 Performance warning.
It looks like the query count of the integration tests increased with this PR.
Database query count is now 206571 was 198420 (+4.1%)
Please check your code again. If you added a new test this can be expected and the base value in tests/integration/base-query-count.txt can be increased.

@luka-nextcloud
luka-nextcloud force-pushed the enhance-datetime-handling branch from 6b2db55 to d733901 Compare October 1, 2026 09:58
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

🐢 Performance warning.
It looks like the query count of the integration tests increased with this PR.
Database query count is now 206568 was 198420 (+4.1%)
Please check your code again. If you added a new test this can be expected and the base value in tests/integration/base-query-count.txt can be increased.

@blizzz blizzz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sqlite is not affected, right?

Json import and Trello imports, are they out of scope, or is it worth checking the year there as well?

Comment thread lib/Command/FixCardDate.php Resolved
parent::__construct();
}

protected function configure() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this is a one time thing to run. What is the motivation to go with a command, not a one-time repair job?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is because admin should input the default year to fix those fields.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, if you were an admin, what would you choose? Like, is there a reason to pick any other number than 9999? What would you pinpoint it at?

Comment on lines +160 to +165
$allowedFormats = [
'Y-m-d',
'Y-m-d H:i:s',
'Y-m-d\TH:i:sP',
'Y-m-d\TH:i:s.v\Z',
];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to we need to be restrictive and selective on formats? Would not passing them to \DateTime(Immutable) and evaluating the year be sufficient?

For, other clients (thinking about the Deck mobile app) might send different formats that have been accepted so far.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth to restrict the formats by allowing common formats. I will check the Deck android app to ensure the format sent from mobile is supported.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blizzz Could you please provide the datetime formats and some sample values sent from the mobile app so I can ensure the validation logic correctly cover those formats? I am not able to run the app because I have no way to get the apk of https://github.com/stefan-niedermann/nextcloud-deck

@blizzz blizzz Oct 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With external clients it can also be someone's curl script that then breaks.

According to Clause, Android Deck does this:

[Certain] Android app source (stefan-niedermann/nextcloud-deck, main branch):

  • deprecated/app/.../GsonUTCInstantAdapter.java serialises with DateTimeFormatter.ISO_INSTANT, giving …T10:15:30Z. That is rejected.
  • data/remote/.../OffsetDateTimeAdapter.java uses ISO_OFFSET_DATE_TIME. That writes Z for UTC and drops :ss when seconds are zero. Both are rejected.

and further

[Likely] So after this PR the app gets a 400 on every card update that has a due date. Third-party clients (n8n, scripts) will hit the same thing. docs/API.md only says "ISO-8601", and it never listed these four formats.

Suggestion:

try {
        $year = (int)(new \DateTimeImmutable($value))->format('Y');
} catch (\Exception) {
        return false;
}
return $year >= 1 && $year <= 9999;

which still validates and is format agnostic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With external clients it can also be someone's curl script that then breaks.
According to Clause, Android Deck does this:

I have updated to add support for formats ISO_INSTANT, ISO_OFFSET_DATE_TIME
I think the suggested code makes no sense since \DateTimeImmutable() returns 2001 for year greater than 9999, causing the result to always be TRUE.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the suggested code makes no sense since \DateTimeImmutable() returns 2001 for year greater than 9999, causing the result to always be TRUE.

Yep, I stand corrected.

OK. Ideally the openapi also announces/documents the allowed formats.

@stefan-niedermann do the formats work for you?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just realized we don't have an openapi spec here yet)

Comment thread lib/Validators/BaseValidator.php Resolved
Comment thread lib/Command/FixCardDate.php Resolved
Comment thread lib/Command/FixCardDate.php Resolved
@luka-nextcloud
luka-nextcloud force-pushed the enhance-datetime-handling branch from d733901 to 6055ec4 Compare October 8, 2026 12:34
@luka-nextcloud

Copy link
Copy Markdown
Contributor Author

sqlite is not affected, right?

Json import and Trello imports, are they out of scope, or is it worth checking the year there as well?

I have just checked. The sqlite was affected. I have updated the command FixCardDate to make it work for sqlite as well.
The date fields are already validated by \DateTime::createFromFormat()
https://github.com/nextcloud/deck/blob/main/lib/Service/Importer/Systems/DeckJsonService.php#L295-L297
https://github.com/nextcloud/deck/blob/main/lib/Service/Importer/Systems/TrelloJsonService.php#L293

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🐢 Performance warning.
It looks like the query count of the integration tests increased with this PR.
Database query count is now 205983 was 198420 (+3.81%)
Please check your code again. If you added a new test this can be expected and the base value in tests/integration/base-query-count.txt can be increased.

Comment thread lib/Command/FixCardDate.php Resolved
@luka-nextcloud
luka-nextcloud force-pushed the enhance-datetime-handling branch from 6055ec4 to be76dbb Compare October 21, 2026 12:28
@github-actions

Copy link
Copy Markdown
Contributor

🐢 Performance warning.
It looks like the query count of the integration tests increased with this PR.
Database query count is now 202767 was 198420 (+2.19%)
Please check your code again. If you added a new test this can be expected and the base value in tests/integration/base-query-count.txt can be increased.

Comment thread lib/Command/FixCardDate.php Resolved

@blizzz blizzz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luka-nextcloud I added a comment for the docs, please double check. Left another comment with a possible change candidate. Otherwise good to go.

@luka-nextcloud
luka-nextcloud force-pushed the enhance-datetime-handling branch from 5bbbfbc to a46669e Compare November 6, 2026 13:42
@luka-nextcloud
luka-nextcloud force-pushed the enhance-datetime-handling branch from a46669e to 3d8f333 Compare November 23, 2026 10:17
@blizzz

blizzz commented Nov 23, 2026

Copy link
Copy Markdown
Member

CI is failing, looks something, more about the activity checkout process.

Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
…e validation to support Java/Android ISO formats

Signed-off-by: Luka Trovic <luka@nextcloud.com>
…ar dates

Signed-off-by: Luka Trovic <luka@nextcloud.com>
Signed-off-by: Luka Trovic <luka@nextcloud.com>
@luka-nextcloud
luka-nextcloud force-pushed the enhance-datetime-handling branch from 3d8f333 to 6a7b756 Compare November 25, 2026 09:27
@luka-nextcloud
luka-nextcloud merged commit 7650cb5 into main Nov 25, 2026
47 of 49 checks passed
@luka-nextcloud
luka-nextcloud deleted the enhance-datetime-handling branch November 25, 2026 12:28
@github-project-automation github-project-automation Bot moved this from 👀 In review to ☑️ Done in 📝 Productivity team Nov 25, 2026
@luka-nextcloud

Copy link
Copy Markdown
Contributor Author

/backport to stable33

@luka-nextcloud

Copy link
Copy Markdown
Contributor Author

/backport to stable34

@backportbot

backportbot Bot commented Nov 25, 2026

Copy link
Copy Markdown

The backport to stable33 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable33
git pull origin stable33

# Create the new backport branch
git checkout -b backport/8388/stable33

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts, resolve them
git cherry-pick 2e0e05c0 ba80d4ec bb74f1f5 2f569873 40494ebe e931fe74 9fb46327 6a7b7566

# Push the cherry pick commit to the remote repository and open a pull request
git push origin backport/8388/stable33

Error: Failed to check for changes with origin/stable33: No changes found in backport branch


Learn more about backports at https://docs.nextcloud.com/server/stable/go.php?to=developer-backports.

@luka-nextcloud

Copy link
Copy Markdown
Contributor Author

/backport to stable35

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

Projects

Status: ☑️ Done

Development

Successfully merging this pull request may close these issues.

Invalid extreme date time value accepted in PostgreSQL causes "Double time specification" error

2 participants