From f23fc192e4739e7b788e4153e6d9f6c77bec8cbf Mon Sep 17 00:00:00 2001 From: Lifei Zhou Date: Tue, 10 Jun 2025 23:02:10 +1000 Subject: [PATCH] fix: added url encoding and decoding for goose recipe url (#2845) --- Cargo.lock | 1 + crates/goose-cli/Cargo.toml | 1 + crates/goose-cli/src/commands/recipe.rs | 3 ++- ui/desktop/src/main.ts | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3679ae3..db3f9894 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3514,6 +3514,7 @@ dependencies = [ "tracing", "tracing-appender", "tracing-subscriber", + "urlencoding", "webbrowser 1.0.4", "winapi", ] diff --git a/crates/goose-cli/Cargo.toml b/crates/goose-cli/Cargo.toml index 4f4294a6..ef4f8dbe 100644 --- a/crates/goose-cli/Cargo.toml +++ b/crates/goose-cli/Cargo.toml @@ -64,6 +64,7 @@ http = "1.0" webbrowser = "1.0" indicatif = "0.17.11" +urlencoding = "2" [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["wincred"] } diff --git a/crates/goose-cli/src/commands/recipe.rs b/crates/goose-cli/src/commands/recipe.rs index 9abc036b..d4c700c2 100644 --- a/crates/goose-cli/src/commands/recipe.rs +++ b/crates/goose-cli/src/commands/recipe.rs @@ -47,7 +47,8 @@ pub fn handle_deeplink(recipe_name: &str) -> Result<()> { style("✓").green().bold(), recipe.title ); - println!("goose://recipe?config={}", deeplink); + let url_safe = urlencoding::encode(&deeplink); + println!("goose://recipe?config={}", url_safe); } Ok(()) } diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index e4b87830..ec87055a 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -254,9 +254,10 @@ app.on('open-url', async (_event, url) => { if (parsedUrl.hostname === 'bot' || parsedUrl.hostname === 'recipe') { let recipeConfig = null; const configParam = parsedUrl.searchParams.get('config'); + const base64 = decodeURIComponent(configParam || ''); if (configParam) { try { - recipeConfig = JSON.parse(Buffer.from(configParam, 'base64').toString('utf-8')); + recipeConfig = JSON.parse(Buffer.from(base64, 'base64').toString('utf-8')); } catch (e) { console.error('Failed to parse bot config:', e); }