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

Commit

Permalink
Reject empty string in Tag::new
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 6, 2023
1 parent f833329 commit c1ea51c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/value/tagged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,15 @@ impl Tag {
///
/// Such a tag would serialize to `!Thing` in YAML regardless of whether a
/// '!' was included in the call to `Tag::new`.
///
/// # Panics
///
/// Panics if `string.is_empty()`. There is no syntax in YAML for an empty
/// tag.
pub fn new(string: impl Into<String>) -> Self {
Tag {
string: string.into(),
}
let tag: String = string.into();
assert!(!tag.is_empty(), "empty YAML tag is not allowed");
Tag { string: tag }
}
}

Expand Down

0 comments on commit c1ea51c

Please sign in to comment.