Skip to content

Commit e4e7ffe

Browse files
committed
filter out also non-printable ascii chars
1 parent 9594e44 commit e4e7ffe

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

src/descriptor/tr.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::str::FromStr;
44
use std::sync::{Arc, Mutex};
55
use std::{fmt, hash};
66

7+
use bitcoin_miniscript::expression::check_valid_chars;
78
use elements::taproot::{
89
LeafVersion, TaprootBuilder, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
910
TAPROOT_CONTROL_MAX_NODE_COUNT, TAPROOT_CONTROL_NODE_SIZE,
@@ -716,11 +717,7 @@ impl<Pk: MiniscriptKey, Ext: Extension> fmt::Display for Tr<Pk, Ext> {
716717

717718
// Helper function to parse string into miniscript tree form
718719
fn parse_tr_tree(s: &str) -> Result<expression::Tree<'_>, Error> {
719-
for ch in s.bytes() {
720-
if !ch.is_ascii() {
721-
return Err(Error::Unprintable(ch));
722-
}
723-
}
720+
check_valid_chars(s)?;
724721

725722
if s.len() > 5 && &s[..5] == "eltr(" && s.as_bytes()[s.len() - 1] == b')' {
726723
let rest = &s[5..s.len() - 1];

src/expression.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use std::fmt;
88
use std::str::FromStr;
99

10+
use bitcoin_miniscript::expression::check_valid_chars;
11+
1012
use crate::{errstr, Error, MAX_RECURSION_DEPTH};
1113

1214
#[derive(Debug, Clone)]
@@ -202,13 +204,7 @@ impl<'a> Tree<'a> {
202204
/// Parses a tree from a string
203205
#[allow(clippy::should_implement_trait)] // seems to be a false positive
204206
pub fn from_str(s: &'a str) -> Result<Tree<'a>, Error> {
205-
// Filter out non-ASCII because we byte-index strings all over the
206-
// place and Rust gets very upsbt when you splinch a string.
207-
for ch in s.bytes() {
208-
if !ch.is_ascii() {
209-
return Err(Error::Unprintable(ch));
210-
}
211-
}
207+
check_valid_chars(s)?;
212208

213209
let (top, rem) = Tree::from_slice(s)?;
214210
if rem.is_empty() {

0 commit comments

Comments
 (0)