fix: validate token description length before sending to Platform#530
fix: validate token description length before sending to Platform#530pauldelucia wants to merge 1 commit intov1.0-devfrom
Conversation
Descriptions must be either empty or 3-100 characters long. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughA 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🟡 MinorUI 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 | 🟡 MinorAdvanced 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).
| 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(), | ||
| ); | ||
| } |
There was a problem hiding this comment.
🧩 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.
| 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).
Descriptions must be either empty or 3-100 characters long.
Summary by CodeRabbit
Release Notes