From 716d167802c62bad8c8c1b3984ab2225912f3b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 8 Nov 2017 09:51:07 +0100 Subject: [PATCH] use safe gsub() call - Fix `dbQuoteString()` and `dbQuoteIdentifier()` to ignore invalid UTF-8 strings (r-dbi/DBItest#156). --- R/quote.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/quote.R b/R/quote.R index 21d25a850..9e3c2e339 100644 --- a/R/quote.R +++ b/R/quote.R @@ -95,7 +95,7 @@ setMethod("dbQuoteIdentifier", c("DBIConnection", "character"), if (any(is.na(x))) { stop("Cannot pass NA to dbQuoteIdentifier()", call. = FALSE) } - x <- gsub('"', '""', x, fixed = TRUE) + x <- gsub('"', '""', enc2utf8(x), fixed = TRUE, useBytes = TRUE) if (length(x) == 0L) { SQL(character()) } else { @@ -152,7 +152,7 @@ setGeneric("dbQuoteString", #' @export setMethod("dbQuoteString", c("DBIConnection", "character"), function(conn, x, ...) { - x <- gsub("'", "''", x, fixed = TRUE) + x <- gsub("'", "''", enc2utf8(x), fixed = TRUE, useBytes = TRUE) if (length(x) == 0L) { SQL(character())