Skip to content
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

Fix #4048, return an error if post title is longer than 200 characters #4188

Closed
wants to merge 3 commits into from

Conversation

varshard
Copy link
Contributor

Fix #4048.

Prevalidate that a post title is longer than 200 characters, which is the length of the post name column on the database. So, that Lemmy could handle the error more gracefully.

@@ -56,6 +55,7 @@ pub async fn create_post(
let url = data_url.map(clean_url_params).map(Into::into); // TODO no good way to handle a "clear"

is_valid_post_title(&data.name)?;
Copy link
Member

Choose a reason for hiding this comment

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

This function already has a check for 200 char maximum length using this regex. But the regex is wrong, it should be something like ^\S{3,200}$ instead. You can change that and add keep your test cases to ensure that its working. I dont think the separate error type for invalid title length is necessary.

Copy link
Contributor Author

@varshard varshard Nov 22, 2023

Choose a reason for hiding this comment

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

Thank you. I shoul've check the regexp.
Look like ^\S{3,200}$ won't work, though. It would reject if a post title contains any space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Nutomic How about ^\s?.{3,200}\s?$ instead?

Copy link
Member

@Nutomic Nutomic Nov 22, 2023

Choose a reason for hiding this comment

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

Right Im not so familiar with regex shorthands. Your suggestion makes more sense, but instead of \s? you can just call trim() so that leading and trailing spaces are removed, not written to db. Also there is no reason to close this PR, you can add more commits to make these changes.

Actually if the regex only checks for string length, it can be removed and replaced with simple comparison of .len().

@Nutomic
Copy link
Member

Nutomic commented Nov 22, 2023

The infinite loading when submitting a post with too long title is a problem in lemmy-ui. I commented in LemmyNet/lemmy-ui#2227 and moved it to lemmy-ui.

@varshard varshard closed this Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants