diff --git a/NEWS.md b/NEWS.md index 25ed942..28e18bf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ * added progress bar for long running queries (#141) by @chainsawriot * added 429 check (#144) * fixed #146 by adding a confirmation step for `auth_setup(browser = FALSE)`(#147) +* fixed #149 by removing quotes around the inputted instance name though `auth_setup(instance = "")` (#150) by @thisisnic # rtoot 0.3.3 diff --git a/R/auth.R b/R/auth.R index b319f58..a898e88 100644 --- a/R/auth.R +++ b/R/auth.R @@ -26,9 +26,7 @@ auth_setup <- function(instance = NULL, type = NULL, name = NULL, path = NULL, c while (is.null(instance) || instance == "") { instance <- rtoot_ask(prompt = "On which instance do you want to authenticate (e.g., \"mastodon.social\")? ", pass = FALSE) } - if(quoted_string(instance)){ - instance <- substr(instance, 2, nchar(instance)-1) - } + instance <- process_instance(instance) #149 client <- get_client(instance = instance) if (!isTRUE(type %in% c("public", "user"))) { type <- c("public", "user")[rtoot_menu(choices = c("public", "user"), title = "What type of token do you want?", verbose = TRUE)] diff --git a/R/utils.R b/R/utils.R index 7c78e43..6a0ef39 100644 --- a/R/utils.R +++ b/R/utils.R @@ -267,6 +267,13 @@ break_process_request <- function(api_response, retryonratelimit = FALSE, verbos } ## a function to determine if input to readline has been quoted or not -quoted_string <- function(x){ - (grepl("^\"", x) && grepl("\"$", x)) || (grepl("^'", x) && grepl("'$", x)) +is_quoted_string <- function(x) { + grepl("^[\"'].+[\"']$", x) +} + +process_instance <- function(x) { + if (!is_quoted_string(x)) { + return(x) + } + gsub("^['\"]+|['\"]+$", "", x) } diff --git a/README.md b/README.md index c38fc09..bfc06c7 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ You can post toots with: post_toot(status = "my first rtoot #rstats") ``` -It can also include media and alt_text. +It can also include media and alt\_text. ``` r post_toot( diff --git a/tests/testthat/test-auth_create_token.R b/tests/testthat/test-auth_create_token.R index 72e5a21..c4fc89b 100644 --- a/tests/testthat/test-auth_create_token.R +++ b/tests/testthat/test-auth_create_token.R @@ -4,3 +4,11 @@ test_that("defensive", { expect_error(create_token(iris), "client is not an object of type rtoot_client") expect_error(create_token(fake_client, type = "elon"), "should be one of") }) + +test_that("test for #149", { + expect_equal(process_instance("\"fosstodon.org\""), "fosstodon.org") + expect_equal(process_instance("\'fosstodon.org\'"), "fosstodon.org") + expect_equal(process_instance("\'\'fosstodon.org\'\'"), "fosstodon.org") + expect_equal(process_instance("fosstodon.org"), "fosstodon.org") + expect_equal(process_instance("fosst\"odon.org"), "fosst\"odon.org") +})