Skip to content

Commit

Permalink
really protect against bad inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Dec 10, 2020
1 parent e624bf2 commit d44010e
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions R/doi.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,22 @@ doiEntryUI <- function(id, width = "100%", ...) {
label = "DOIs",
placeholder = "Enter your DOIs here.",
width = width,
rows = 10L
rows = 15L
),
shiny::actionButton(
inputId = ns("validate"),
label = "Validate your DOIs",
width = width
),
shiny::div(
shiny::p("Found these DOIs:")
),
shiny::textOutput(
outputId = ns("found")
shiny::p(
"Found ",
shiny::textOutput(
outputId = ns("found"),
inline = TRUE
),
" DOIS."
)
)
)
}
Expand All @@ -120,15 +124,24 @@ doiEntryServer <- function(id) {
# input validation
iv <- shinyvalidate::InputValidator$new()
iv$add_rule("entered", shinyvalidate::sv_required())
iv$add_rule("entered", ~ if (nchar(.) > 1000) "Too many DOIs.")
iv$add_rule("entered", ~ if (nchar(.) > 10000L) "Too many DOIs.")
iv$enable()

# ingestion
# ingest
dois <- shiny::eventReactive(input$validate, {
unique(tolower(as.vector(str_extract_all_doi(input$entered))))
if (iv$is_valid()) {
unique(tolower(as.vector(str_extract_all_doi(input$entered))))
} else {
shiny::showNotification(
"Please fix the errors in the form before continuing",
type = "warning"
)
NULL
}
})

output$found <- shiny::renderText({
dois()
length(dois())
})
dois
}
Expand Down

0 comments on commit d44010e

Please sign in to comment.