Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions crates/metadata/src/specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

#![allow(clippy::new_ret_no_self)]

use crate::serde_hex;
use crate::{
serde_hex,
utils::trim_extra_whitespace,
};
#[cfg(not(feature = "std"))]
use alloc::{
format,
Expand Down Expand Up @@ -367,7 +370,10 @@ impl<S, P> ConstructorSpecBuilder<S, P> {
{
let mut this = self;
debug_assert!(this.spec.docs.is_empty());
this.spec.docs = docs.into_iter().map(str::trim).collect::<Vec<_>>();
this.spec.docs = docs
.into_iter()
.map(trim_extra_whitespace)
.collect::<Vec<_>>();
this
}
}
Expand Down Expand Up @@ -586,7 +592,10 @@ impl<S, M, P, R> MessageSpecBuilder<S, M, P, R> {
{
let mut this = self;
debug_assert!(this.spec.docs.is_empty());
this.spec.docs = docs.into_iter().collect::<Vec<_>>();
this.spec.docs = docs
.into_iter()
.map(trim_extra_whitespace)
Copy link
Collaborator

@ascjones ascjones Sep 5, 2022

Choose a reason for hiding this comment

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

Good spot, could you update the trim_docs test: https://github.com/paritytech/ink/blob/47b1fa3291dd7551002e780ace31df4d80e8539d/crates/metadata/src/tests.rs#L180 (or add a new one) to cover this, and also to test the updated trimming logic?

.collect::<Vec<_>>();
this
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/metadata/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use crate::serde_hex;
use std::str;

/// Serializes the given bytes as byte string.
pub fn serialize_as_byte_str<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error>
Expand Down Expand Up @@ -56,3 +57,11 @@ where

deserializer.deserialize_str(Visitor)
}

pub fn trim_extra_whitespace(item: &'static str) -> &'static str {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub fn trim_extra_whitespace(item: &'static str) -> &'static str {
pub fn trim_extra_whitespace(item: &str) -> &str {

Lifetimes can be elided

if let Some(stripped) = item.strip_prefix(' ') {
stripped.trim_end()
} else {
item.trim_end()
}
}