Skip to content

Commit b4fd8e9

Browse files
committed
Extract sanitize helper
1 parent 3064886 commit b4fd8e9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

bin/ruby-build

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ capitalize() {
6161
printf "%s" "$1" | tr a-z A-Z
6262
}
6363

64+
sanitize() {
65+
printf "%s" "$1" | sed "s/[^A-Za-z0-9.-]/_/g; s/__*/_/g"
66+
}
67+
6468
build_failed() {
6569
{ echo
6670
echo "BUILD FAILED"
@@ -294,10 +298,10 @@ fetch_git() {
294298
if type git &>/dev/null; then
295299
if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
296300
pushd "$RUBY_BUILD_CACHE_PATH" >&4
297-
local clone_name=$(echo $git_url | sed "s/[^A-Za-z0-9.-]/_/g; s/__*/_/g")
301+
local clone_name="$(sanitize "$git_url")"
298302
if [ -e "${clone_name}" ]; then
299303
{ cd "${clone_name}"
300-
git fetch --force "$git_url" "+${git_ref}:${git_ref}"
304+
git fetch --force "$git_url" "+${git_ref}:${git_ref}"
301305
} >&4 2>&1
302306
else
303307
git clone --bare --branch "$git_ref" "$git_url" "${clone_name}" >&4 2>&1

0 commit comments

Comments
 (0)