Skip to content

Commit c52909a

Browse files
committed
use modern jsonlite::parse_json for safer JSON parsing
1 parent f293486 commit c52909a

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Imports:
2727
tools,
2828
scales,
2929
httr,
30-
jsonlite,
30+
jsonlite (>= 1.6),
3131
magrittr,
3232
digest,
3333
viridisLite,

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ importFrom(httr,config)
246246
importFrom(httr,content)
247247
importFrom(httr,stop_for_status)
248248
importFrom(httr,warn_for_status)
249-
importFrom(jsonlite,fromJSON)
249+
importFrom(jsonlite,parse_json)
250+
importFrom(jsonlite,read_json)
250251
importFrom(jsonlite,toJSON)
251252
importFrom(lazyeval,all_dots)
252253
importFrom(lazyeval,f_eval)

R/imports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @importFrom stats setNames complete.cases quantile is.leaf
66
#' @importFrom tidyr unnest
77
#' @importFrom viridisLite viridis
8-
#' @importFrom jsonlite toJSON fromJSON
8+
#' @importFrom jsonlite toJSON parse_json read_json
99
#' @importFrom httr GET POST PATCH content config add_headers stop_for_status warn_for_status
1010
#' @importFrom htmlwidgets createWidget sizingPolicy saveWidget onRender prependContent
1111
#' @importFrom lazyeval f_eval is_formula all_dots is_lang f_new

R/shiny.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ renderPlotly <- function(expr, env = parent.frame(), quoted = FALSE) {
4646
shiny::snapshotPreprocessOutput(
4747
renderFunc,
4848
function(value) {
49-
json <- from_JSON_safe(value)
49+
json <- from_JSON(value)
5050
json$x <- json$x[setdiff(names(json$x), c("visdat", "cur_data", "attrs"))]
5151
to_JSON(json)
5252
}
@@ -103,7 +103,7 @@ event_data <- function(
103103
val <- session$rootScope()$input[[src]]
104104

105105
# legend clicking returns trace(s), which shouldn't be simplified...
106-
fromJSONfunc <- if (event %in% c("plotly_legendclick", "plotly_legenddoubleclick")) from_JSON else jsonlite::fromJSON
106+
fromJSONfunc <- if (event %in% c("plotly_legendclick", "plotly_legenddoubleclick")) from_JSON else jsonlite::parse_json
107107

108108
if (is.null(val)) val else fromJSONfunc(val)
109109
}

R/utils.R

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ grab <- function(what = "username") {
948948

949949
# try to grab an object key from a JSON file (returns empty string on error)
950950
try_file <- function(f, what) {
951-
tryCatch(jsonlite::fromJSON(f)[[what]], error = function(e) NULL)
951+
tryCatch(jsonlite::read_json(f)[[what]], error = function(e) NULL)
952952
}
953953

954954
# preferred defaults for toJSON mapping
@@ -959,14 +959,7 @@ to_JSON <- function(x, ...) {
959959

960960
# preferred defaults for toJSON mapping
961961
from_JSON <- function(x, ...) {
962-
jsonlite::fromJSON(x, simplifyDataFrame = FALSE, simplifyMatrix = FALSE, ...)
963-
}
964-
965-
from_JSON_safe <- function(txt, ...) {
966-
if (!jsonlite::validate(txt)) {
967-
stop("Expected a valid JSON string.")
968-
}
969-
from_JSON(txt, ...)
962+
jsonlite::parse_json(x, simplifyDataFrame = FALSE, simplifyMatrix = FALSE, ...)
970963
}
971964

972965
i <- function(x) {

0 commit comments

Comments
 (0)