Skip to content

Conversation

@tipogi
Copy link
Contributor

@tipogi tipogi commented Dec 4, 2025

Summary

Adds comprehensive validation rules across all data models, refactors constants organization, and separates sanitization from validation logic.

Key Changes

Code Organization

  • Created src/constants.rs to centralize all constants
  • Moved tag validation constants to shared location

Validation Enhancements

Tags:

  • Reusable sanitize_tag_label() and validate_tag_label() functions
  • Shared validation between PubkyAppTag and PubkyAppFeed

Feeds:

  • Maximum 5 tags per feed
  • Tag validation using shared functions

Posts:

  • Attachment validation: max 10 attachments, max 200 chars per URL
  • Protocol whitelist: pubky://, http://, https://, ipfs://, ipns://
  • Reserved keyword protection: prevents [DELETED] content

Users:

  • Image URL format validation
  • Enhanced link validation (empty checks, format validation)

Sanitization vs Validation

  • Before: Sanitization truncated fields exceeding limits
  • After: Sanitization only normalizes (trim, lowercase), validation enforces limits

Problems Solved

  1. Missing validation rules (attachments, tag counts, protocols)
  2. Code duplication in tag validation
  3. Mixed sanitization/validation logic
  4. Poor error messages
  5. Insufficient test coverage

Files Changed

  • src/constants.rs (new) - Centralized constants
  • src/models/tag.rs - Reusable validation functions
  • src/models/feed.rs - Tag validation
  • src/models/post.rs - Attachment & content validation
  • src/models/user.rs - Enhanced field validation
  • src/models/blob.rs, file.rs - Test improvements
  • src/common.rs, lib.rs, utils.rs, uri_parser.rs - Import updates

Impact

✅ Better data integrity | ✅ Clearer error messages | ✅ Reusable validation functions | ✅ Comprehensive tests

⚠️ Breaking: Sanitization no longer truncates - validation must be called separately

@tipogi tipogi self-assigned this Dec 4, 2025
@tipogi tipogi added the chore label Dec 4, 2025
@tipogi tipogi requested review from catch-21 and ok300 December 4, 2025 14:49
@tipogi tipogi marked this pull request as ready for review December 4, 2025 17:23
@tipogi
Copy link
Contributor Author

tipogi commented Dec 4, 2025

Thanks @catch-21 for the help!

@ok300
Copy link
Contributor

ok300 commented Dec 7, 2025

I think this fixes #35

@tipogi tipogi linked an issue Dec 8, 2025 that may be closed by this pull request
@ok300 ok300 requested a review from SHAcollision December 12, 2025 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: blob size validation.

4 participants