From 7615a0578d0b473ed16db9989da860348fe8e059 Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Thu, 2 Nov 2023 22:41:20 +0100 Subject: [PATCH] improve error on empty string invoice --- libs/sdk-core/src/invoice.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/sdk-core/src/invoice.rs b/libs/sdk-core/src/invoice.rs index 36637f3da..5230a8ef4 100644 --- a/libs/sdk-core/src/invoice.rs +++ b/libs/sdk-core/src/invoice.rs @@ -1,3 +1,4 @@ +use anyhow::anyhow; use bitcoin::secp256k1::{self, PublicKey}; use hex::ToHex; use lightning::routing::gossip::RoutingFees; @@ -189,6 +190,11 @@ pub fn add_lsp_routing_hints( /// Parse a BOLT11 payment request and return a structure contains the parsed fields. pub fn parse_invoice(bolt11: &str) -> InvoiceResult { + if bolt11.trim().is_empty() { + return Err(InvoiceError::Validation(anyhow!( + "bolt11 is an empty string" + ))); + } let re = Regex::new(r"(?i)^lightning:")?; let bolt11 = re.replace_all(bolt11, ""); let signed = bolt11.parse::()?;