Skip to content

fix: validate token description length before sending to Platform#530

Open
pauldelucia wants to merge 1 commit intov1.0-devfrom
feat/validate-token-description-length
Open

fix: validate token description length before sending to Platform#530
pauldelucia wants to merge 1 commit intov1.0-devfrom
feat/validate-token-description-length

Conversation

@pauldelucia
Copy link
Member

@pauldelucia pauldelucia commented Feb 5, 2026

Descriptions must be either empty or 3-100 characters long.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Added validation for token descriptions. When creating a token, descriptions must be between 3 and 100 characters if provided, or left empty. Users will receive an error message if they attempt to submit an invalid description length.

Descriptions must be either empty or 3-100 characters long.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

A validation constraint is added to token description input during token argument parsing. When a description is provided, it must be 3 to 100 characters in length; otherwise, parsing fails with a validation error message.

Changes

Cohort / File(s) Summary
Token Description Validation
src/ui/tokens/tokens_screen/token_creator.rs
Adds validation gate in parse_token_build_args requiring non-empty token descriptions to have length between 3 and 100 characters, returning an error if constraint is violated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

🐰 A token's tale, once wild and free,
Now polished by a boundary!
Three to one-hundred chars divine,
Make descriptions perfectly fine.
Validation hops along the way,
Keeping chaos at bay! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding validation for token description length before sending to the Platform, which matches the core objective of enforcing the 3-100 character constraint.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/validate-token-description-length

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/ui/tokens/tokens_screen/token_creator.rs (2)

335-344: ⚠️ Potential issue | 🟡 Minor

UI hint doesn't mention the 3-character minimum requirement.

The info tooltip says "Maximum 100 characters" but the validation (line 1281-1286) requires descriptions to be either empty or 3-100 characters. Users entering 1-2 character descriptions will get an unexpected error.

Consider updating the hint to clarify the minimum requirement.

📝 Proposed fix
                                     ui.horizontal(|ui| {
                                         ui.label("Description:");
                                         if crate::ui::helpers::info_icon_button(ui,
                                             "An optional description explaining what your token is for.\n\n\
                                             This helps users understand the purpose of your token.\n\n\
-                                            Maximum 100 characters.").clicked() {
+                                            If provided, must be between 3 and 100 characters.").clicked() {
                                             self.show_pop_up_info = Some(
                                                 "Description\n\n\
                                                 An optional description explaining what your token is for.\n\n\
                                                 This helps users understand the purpose of your token.\n\n\
-                                                Maximum 100 characters.".to_string()
+                                                If provided, must be between 3 and 100 characters.".to_string()
                                             );
                                         }
                                     });

687-689: ⚠️ Potential issue | 🟡 Minor

Advanced mode label also missing minimum requirement.

Same issue as simple mode - the label says "max 100 chars" but validation requires 3-100 characters if non-empty.

📝 Proposed fix
                                 // Row 5: Token Description
-                                ui.label("Token Description (max 100 chars):");
+                                ui.label("Token Description (3-100 chars, optional):");
                                 ui.text_edit_singleline(&mut self.token_description_input);
                                 ui.end_row();
🤖 Fix all issues with AI agents
In `@src/ui/tokens/tokens_screen/token_creator.rs`:
- Around line 1280-1286: The validation currently uses byte-length via
self.token_description_input.len(); replace this with a character count using
self.token_description_input.chars().count() and use that value for the 3–100
characters check so multi-byte UTF‑8 characters (emoji, CJK, etc.) are measured
correctly; update the conditional that references len and ensure the error
message remains the same but now reflects character-based validation (refer to
the token_description_input variable and the surrounding validation block).

Comment on lines +1280 to +1286
let len = self.token_description_input.len();
if len < 3 || len > 100 {
return Err(
"Token description must be either empty or between 3 and 100 characters long"
.to_string(),
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

Dash Platform token description validation length requirements

💡 Result:

On Dash Platform, a token’s description field is validated to be between 3 and 100 characters (inclusive), per the token constraints in the Platform protocol documentation. [1]


🌐 Web query:

Dash Platform string validation bytes vs characters UTF-8

💡 Result:

On Dash Platform, a string’s minLength / maxLength in a data contract follows JSON Schema (draft 2020-12) rules—i.e., it is measured in characters, not bytes. JSON Schema defines string length as “the number of its characters as defined by RFC 8259” (JSON text / Unicode), not UTF‑8 byte length. [1]

However, Dash Platform also enforces byte-size caps at the protocol level (independent of maxLength), including:

  • Maximum field value size: 5120 bytes [2]
  • Maximum state transition size: 20480 bytes [2]

So the practical limit for a string field is:

  • maxLength (characters) AND
  • the platform’s byte limit for the serialized field/value (meaning UTF‑8 multi-byte characters can hit the 5120-byte cap before reaching your maxLength).

Also note: if you use pattern or format on a string, Dash requires you to define maxLength (up to 50,000). [3]

Sources: JSON Schema Validation (2020-12) [1], Dash Platform Data Contract docs (size limits) [2], Dash Platform contract keyword constraints (pattern/format require maxLength) [3].


Use .chars().count() instead of .len() for character-length validation.

Dash Platform validates the token description field as 3–100 characters per JSON Schema rules, which measure string length in characters, not UTF-8 bytes. The current code uses String::len(), which counts bytes. For multi-byte UTF-8 characters (emoji, CJK, accented letters), this causes incorrect validation—e.g., "🚀🚀🚀" (3 characters, 12 bytes) would be rejected despite meeting the requirement.

♻️ Fix
-            let len = self.token_description_input.len();
+            let len = self.token_description_input.chars().count();
             if len < 3 || len > 100 {
                 return Err(
                     "Token description must be either empty or between 3 and 100 characters long"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let len = self.token_description_input.len();
if len < 3 || len > 100 {
return Err(
"Token description must be either empty or between 3 and 100 characters long"
.to_string(),
);
}
let len = self.token_description_input.chars().count();
if len < 3 || len > 100 {
return Err(
"Token description must be either empty or between 3 and 100 characters long"
.to_string(),
);
}
🤖 Prompt for AI Agents
In `@src/ui/tokens/tokens_screen/token_creator.rs` around lines 1280 - 1286, The
validation currently uses byte-length via self.token_description_input.len();
replace this with a character count using
self.token_description_input.chars().count() and use that value for the 3–100
characters check so multi-byte UTF‑8 characters (emoji, CJK, etc.) are measured
correctly; update the conditional that references len and ensure the error
message remains the same but now reflects character-based validation (refer to
the token_description_input variable and the surrounding validation block).

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

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

ci failing

@lklimek lklimek self-requested a review as a code owner February 24, 2026 20:15
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.

2 participants