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: sanitize image filenames for writing to disk #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions R/download_view_filtered.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#'
#' Downloads PNG images of filtered Tableau views based on the provided dataframe containing filter columns and filter values.
#'
#' This function sanitizes filenames by removing forbidden characters.
#' However, there is a risk of overwriting existing images if the only difference in filter values
#' is the presence of forbidden characters.
#' Users should be aware of this potential issue when using the function.
#'
#' @param tableau A list containing the Tableau authentication variables: `base_url`, `token`, `user_id`, and `site_id`.
#' @param df Dataframe containing filter columns and filter values.
#' @param view_id The ID of the view to download.
Expand Down Expand Up @@ -65,17 +70,17 @@ row_to_query <- function(row) {
return(query)
}

#' Concat row to name
#' Concat row to name with sanitization
#'
#' @param row row of dataframe
#'
#' @return namr of the row
#' @return sanitized name of the row
row_to_name <- function(row) {
# Use paste to concatenate "vf_", column names, "=", and row values
filter_strs <- paste0(as.character(row), collapse = "")

# Combine the filter strings with "&" and prepend "?"
query <- paste0((filter_strs))
# Sanitize the filename by removing forbidden characters
sanitized_name <- gsub("[<>:\"/\\|?*]", "_", filter_strs) # Replace forbidden characters with underscore

return(query)
return(sanitized_name)
}
6 changes: 6 additions & 0 deletions man/download_filtered_tableau_image.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/row_to_name.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading