Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

feat: validate petnames and slugs disallowing an empty string #382

Merged
merged 1 commit into from
May 12, 2023
Merged

Conversation

jsantell
Copy link
Contributor

No description provided.

@jsantell jsantell requested a review from cdata May 12, 2023 00:43
Copy link
Collaborator

@cdata cdata left a comment

Choose a reason for hiding this comment

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

One thing that strikes me, reading through this: there are a number of places where "slug" or "petname" is the intended argument, and these are really stringly typed values. For example, if we validate the slug format on writes, we should probably also do it on reads.

We've previously adapted to stringly types by making concrete wrapper types for them. Maybe this is a case where we need a Slug and Petname wrapper type that can only be initialized on a code path that performs validation. Then, we can change all the related signatures to use this wrapper type instead.

WDYT?

rust/noosphere-sphere/src/content/write.rs Outdated Show resolved Hide resolved
rust/noosphere-sphere/src/content/write.rs Show resolved Hide resolved
@jsantell
Copy link
Contributor Author

One thing that strikes me, reading through this: there are a number of places where "slug" or "petname" is the intended argument, and these are really stringly typed values. For example, if we validate the slug format on writes, we should probably also do it on reads.

We've previously adapted to stringly types by making concrete wrapper types for them. Maybe this is a case where we need a Slug and Petname wrapper type that can only be initialized on a code path that performs validation. Then, we can change all the related signatures to use this wrapper type instead.

WDYT?

Rationale behind guarding writes and not reads: we could introduce an invalid petname/slug somewhere, and at least we'll be able to query its existence and read/delete it (even in tests). On the contrast, assuming that all slug/petnames are valid internally in non-writes could cause an issue.

Because the values aren't (yet?) restrictive (only guarding against empty strings) or have multiple interpretations (ucan/nsrecord/jwt), I'm bearish on new String-types for Petname/Slug

@cdata
Copy link
Collaborator

cdata commented May 12, 2023

Filed #385 for potential future exploration here.

@jsantell jsantell requested a review from cdata May 12, 2023 18:01
Copy link
Collaborator

@cdata cdata left a comment

Choose a reason for hiding this comment

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

Nice, LGTM

@cdata cdata merged commit fdda233 into main May 12, 2023
@github-actions github-actions bot mentioned this pull request May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants