Skip to content

Commit 81d38f7

Browse files
authored
Fix: check_handle should apply the whitespace trimming and collapsing (#2363)
# Goal The goal of this PR is to update the check_handle Runtime RPC to correctly use the whitespace trim and collapse Closes #2362 # Discussion - I thought about updating how this gets the value to be more aligned, but in the end the simple fix won out. # Checklist - [x] Unit Tests added? - [x] Spec version incremented?
1 parent dac1458 commit 81d38f7

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ onboard:
9191
./scripts/init.sh onboard-frequency-paseo-local
9292

9393
.PHONY: onboard-res-local
94-
onboard-debug:
94+
onboard-res-local:
9595
./scripts/init.sh onboard-res-local
9696

9797
.PHONY: onboard-docker

pallets/handles/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ pub mod pallet {
592592

593593
let base_handle_str = core::str::from_utf8(&base_handle).unwrap_or_default();
594594

595+
let base_handle_trimmed = trim_and_collapse_whitespace(base_handle_str);
596+
595597
// Convert base handle into a canonical base
596598
let (_canonical_handle_str, canonical_base) =
597599
Self::get_canonical_string_vec_from_base_handle(base_handle_str);
@@ -603,7 +605,7 @@ pub mod pallet {
603605
let suffixes_available = suffix_index < T::HandleSuffixMax::get();
604606

605607
CheckHandleResponse {
606-
base_handle,
608+
base_handle: base_handle_trimmed.into(),
607609
suffix_index,
608610
suffixes_available,
609611
valid,

pallets/handles/src/tests/handle_creation_tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,18 @@ fn test_check_handle() {
438438
}
439439
);
440440

441+
let good_whitespace_handle: String = String::from(" hel lo ");
442+
assert_eq!(
443+
Handles::check_handle(good_whitespace_handle.as_bytes().to_vec()),
444+
CheckHandleResponse {
445+
base_handle: "hel lo".as_bytes().to_vec(),
446+
suffix_index: 0,
447+
suffixes_available: true,
448+
valid: true,
449+
canonical_base: String::from("he110").as_bytes().to_vec(),
450+
}
451+
);
452+
441453
let too_long_handle: String = "*".repeat((HANDLE_BYTES_MAX + 1) as usize);
442454
assert_eq!(
443455
Handles::check_handle(too_long_handle.as_bytes().to_vec()),

runtime/frequency/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
435435
spec_name: Cow::Borrowed("frequency"),
436436
impl_name: Cow::Borrowed("frequency"),
437437
authoring_version: 1,
438-
spec_version: 153,
438+
spec_version: 154,
439439
impl_version: 0,
440440
apis: RUNTIME_API_VERSIONS,
441441
transaction_version: 1,
@@ -449,7 +449,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
449449
spec_name: Cow::Borrowed("frequency-testnet"),
450450
impl_name: Cow::Borrowed("frequency"),
451451
authoring_version: 1,
452-
spec_version: 153,
452+
spec_version: 154,
453453
impl_version: 0,
454454
apis: RUNTIME_API_VERSIONS,
455455
transaction_version: 1,

0 commit comments

Comments
 (0)