Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update plugin-add regex to support other languages #1241

Merged
merged 1 commit into from Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/functions/plugins.bash
Expand Up @@ -56,8 +56,9 @@ plugin_add_command() {

local plugin_name=$1

if ! printf "%s" "$plugin_name" | grep -q -E "^[a-zA-Z0-9_-]+$"; then
display_error "$plugin_name is invalid. Name must match regex ^[a-zA-Z0-9_-]+$"
local regex="^[[:alpha:][:digit:]_-]+$"
if ! printf "%s" "$plugin_name" | grep -q -E "$regex"; then
display_error "$plugin_name is invalid. Name must match regex $regex"
exit 1
fi

Expand Down
20 changes: 18 additions & 2 deletions test/plugin_add_command.bats
Expand Up @@ -20,16 +20,32 @@ teardown() {
[ "$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" {
ORIGINAL_LANG="$LANG"
LANG=sv_SE.UTF-8

install_mock_plugin_repo "plugin-with-w"

# https://stackoverflow.com/questions/52570103/regular-expression-a-za-z-seems-to-not-include-letter-w-and-wA
# https://github.com/asdf-vm/asdf/issues/1237
run asdf plugin add "plugin-with-w" "${BASE_DIR}/repo-plugin-with-w"
[ "$status" -eq 0 ]

run asdf plugin-list
[ "$output" = "plugin-with-w" ]

LANG="$ORIGINAL_LANG"
}
@test "plugin_add command with plugin name not matching valid regex fails" {
run asdf plugin add "invalid\$plugin\$name"
[ "$status" -eq 1 ]
[ "$output" = "invalid\$plugin\$name is invalid. Name must match regex ^[a-zA-Z0-9_-]+$" ]
[ "$output" = "invalid\$plugin\$name is invalid. Name must match regex ^[[:alpha:][:digit:]_-]+$" ]
}

@test "plugin_add command with plugin name not matching valid regex fails again" {
run asdf plugin add "#invalid#plugin#name"
[ "$status" -eq 1 ]
[ "$output" = "#invalid#plugin#name is invalid. Name must match regex ^[a-zA-Z0-9_-]+$" ]
[ "$output" = "#invalid#plugin#name is invalid. Name must match regex ^[[:alpha:][:digit:]_-]+$" ]
}

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