Escape strings that may comes from remote sources

Use printf "%q" to escape branch names.
This commit is contained in:
nojhan 2013-03-13 15:58:56 +01:00
parent b7ffd46f9b
commit 92bd933905

View File

@ -317,6 +317,13 @@ unset _lp_source_config
[[ "$LP_ENABLE_BZR" = 1 ]] && { command -v bzr > /dev/null || LP_ENABLE_BZR=0 ; }
[[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; }
# Escape the given strings
# Must be used for all strings that may comes from remote sources,
# like VCS branch names
_lp_escape()
{
printf "%q" "$*"
}
###############
@ -688,7 +695,8 @@ _lp_git_branch()
branch="$(git rev-parse --short HEAD 2>/dev/null)"
fi
[[ $? -ne 0 || -z "$branch" ]] && return
echo "${branch#refs/heads/}"
branch="${branch#refs/heads/}"
echo $(_lp_escape "$branch")
}
# Set a color depending on the branch state:
@ -772,7 +780,8 @@ _lp_hg_branch()
[[ "$LP_ENABLE_HG" != 1 ]] && return
local branch
branch="$(hg branch 2>/dev/null)"
[[ $? -eq 0 ]] && echo "$branch"
[[ $? -eq 0 ]] && echo $(_lp_escape "$branch")
}
# Set a color depending on the branch state:
@ -813,7 +822,7 @@ _lp_svn_branch()
echo trunk
else
result=$(expr "$url" : '.*/branches/\([^/]*\)' || expr "$url" : '/\([^/]*\)' || basename "$root")
echo $result
echo $(_lp_escape "$result")
fi
}
@ -851,7 +860,7 @@ _lp_fossil_branch()
local branch
branch=$(fossil status 2>/dev/null | grep tags: | cut -c17-)
if [[ -n "$branch" ]] ; then
echo "$branch"
echo $(_lp_escape "$branch")
else
if fossil info &>/dev/null ; then
echo "no-tag"
@ -920,7 +929,7 @@ _lp_fossil_branch_color()
branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}"
fi
fi
echo -ne "$branch"
echo $(_lp_escape "$branch")
fi
}
@ -930,10 +939,10 @@ _lp_fossil_branch_color()
_lp_bzr_branch()
{
[[ "$LP_ENABLE_BZR" != 1 ]] && return
local output
output=$(bzr nick 2> /dev/null)
local branch
branch=$(bzr nick 2> /dev/null)
[[ $? -ne 0 ]] && return
echo "$output"
echo $(_lp_escape "$branch")
}