From 8705353dafc5e0e4ae5645193518b2e99df0b9c6 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Tue, 6 May 2025 17:28:59 +0300 Subject: [PATCH] fix: trim branch before uriencode --- git-open.zsh | 8 ++++++-- tests/test.zsh | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/git-open.zsh b/git-open.zsh index fb979a9..0eea38f 100755 --- a/git-open.zsh +++ b/git-open.zsh @@ -17,6 +17,10 @@ uriencode() { done } +trim() { + echo "$1" | sed -E 's/^[ \t]+|[ \t]+$//g' +} + git_get_remote() { remote=$(git remote -v | grep "(push)" | awk '{print $2}') echo $remote @@ -214,8 +218,8 @@ git_open_new_pr() { default_branch="master" fi - branch=$(uriencode $branch) - default_branch=$(uriencode $default_branch) + branch="$(uriencode $(trim $branch))" + default_branch="$(uriencode $(trim $default_branch))" case "$remote_type" in github) open_url "$silent" "https://github.com/$repo_path/compare/$default_branch...$branch" ;; diff --git a/tests/test.zsh b/tests/test.zsh index cb61c63..f5d8028 100755 --- a/tests/test.zsh +++ b/tests/test.zsh @@ -79,6 +79,7 @@ describe "git_open_new_pr" assert_value "https://github.com/chenasraf/git-open/compare/develop...master" $(git_open_new_pr -f master develop) assert_value "https://github.com/chenasraf/git-open/compare/master...develop" $(git_open_new_pr -f develop) assert_value "https://github.com/chenasraf/git-open/compare/master...$current_branch" $(git_open_new_pr -f) +assert_value "https://github.com/chenasraf/git-open/compare/develop...master" $(git_open_new_pr -f "master " " develop ") describe "git_open_pipelines" assert_value "https://github.com/chenasraf/git-open/actions" $(git_open_pipelines)