Skip to content

Commit

Permalink
fix: force lwrcase plugin name fix capitalization mismatch errs (#1400)
Browse files Browse the repository at this point in the history
Co-authored-by: Trevor Brown <[email protected]>
Closes #816
  • Loading branch information
hyperupcall authored Dec 29, 2022
1 parent a4bf582 commit 196a05b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/functions/plugins.bash
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ plugin_add_command() {

local plugin_name=$1

local regex="^[[:alpha:][:digit:]_-]+$"
local regex="^[[:lower:][:digit:]_-]+$"
if ! printf "%s" "$plugin_name" | grep -q -E "$regex"; then
display_error "$plugin_name is invalid. Name must match regex $regex"
display_error "$plugin_name is invalid. Name may only contain lowercase letters, numbers, '_', and '-'"
exit 1
fi

Expand Down
21 changes: 14 additions & 7 deletions test/plugin_add_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ teardown() {
}

@test "plugin_add command with plugin name matching all valid regex chars succeeds" {
install_mock_plugin_repo "plugin_with-all-valid-CHARS-123"
install_mock_plugin_repo "plugin_with-all-valid-chars-123"

run asdf plugin add "plugin_with-all-valid-CHARS-123" "${BASE_DIR}/repo-plugin_with-all-valid-CHARS-123"
run asdf plugin add "plugin_with-all-valid-chars-123" "${BASE_DIR}/repo-plugin_with-all-valid-chars-123"
[ "$status" -eq 0 ]

run asdf plugin list
[ "$output" = "plugin_with-all-valid-CHARS-123" ]
[ "$output" = "plugin_with-all-valid-chars-123" ]
}

@test "plugin_add command with LANG=sv_SE.UTF-8 and plugin name matching all valid regex chars succeeds" {
Expand All @@ -36,16 +36,23 @@ teardown() {

LANG="$ORIGINAL_LANG"
}
@test "plugin_add command with plugin name not matching valid regex fails" {

@test "plugin_add command with plugin name not matching valid regex fails 1" {
run asdf plugin add "invalid\$plugin\$name"
[ "$status" -eq 1 ]
[ "$output" = "invalid\$plugin\$name is invalid. Name must match regex ^[[:alpha:][:digit:]_-]+$" ]
[ "$output" = "invalid\$plugin\$name is invalid. Name may only contain lowercase letters, numbers, '_', and '-'" ]
}

@test "plugin_add command with plugin name not matching valid regex fails again" {
@test "plugin_add command with plugin name not matching valid regex fails 2" {
run asdf plugin add "#invalid#plugin#name"
[ "$status" -eq 1 ]
[ "$output" = "#invalid#plugin#name is invalid. Name must match regex ^[[:alpha:][:digit:]_-]+$" ]
[ "$output" = "#invalid#plugin#name is invalid. Name may only contain lowercase letters, numbers, '_', and '-'" ]
}

@test "plugin_add command with plugin name not matching valid regex fails 3" {
run asdf plugin add "Ruby"
[ "$status" -eq 1 ]
[ "$output" = "Ruby is invalid. Name may only contain lowercase letters, numbers, '_', and '-'" ]
}

@test "plugin_add command with no URL specified adds a plugin using repo" {
Expand Down

0 comments on commit 196a05b

Please sign in to comment.