Encode strings to UTF-8 for URLencode
Fixes umlaut queries on windows.
Resolves #3
Change-Id: Ic2ec22a595b5e167abbf374ce4c8e8375837f0b9
diff --git a/NEWS.md b/NEWS.md
index 99b437f..88a6648 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,4 +1,5 @@
## Bug Fixes
+- fixed umlaut queries on windows
- fixed retrieval of access token when multiple access tokens are stored
# RKorAPClient 0.6.1
diff --git a/R/KorAPCorpusStats.R b/R/KorAPCorpusStats.R
index 8d9545a..8c4ad47 100644
--- a/R/KorAPCorpusStats.R
+++ b/R/KorAPCorpusStats.R
@@ -44,7 +44,7 @@
url <-
paste0(kco@apiUrl,
'statistics?cq=',
- URLencode(vc, reserved = TRUE))
+ URLencode(enc2utf8(vc), reserved = TRUE))
log.info(verbose, "Getting size of virtual corpus \"", vc, "\"", sep = "")
res <- apiCall(kco, url)
log.info(verbose, ": ", res$tokens, " tokens\n")
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 230eb24..0b07106 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -168,8 +168,8 @@
}
request <-
paste0('?q=',
- URLencode(query, reserved = TRUE),
- if (vc != '') paste0('&cq=', URLencode(vc, reserved = TRUE)) else '', '&ql=', ql)
+ URLencode(enc2utf8(query), reserved = TRUE),
+ if (vc != '') paste0('&cq=', URLencode(enc2utf8(vc), reserved = TRUE)) else '', '&ql=', ql)
webUIRequestUrl <- paste0(kco@KorAPUrl, request)
requestUrl <- paste0(
kco@apiUrl,
diff --git a/tests/testthat/test-corpusQuery.R b/tests/testthat/test-corpusQuery.R
index 72b9f36..df512cd 100644
--- a/tests/testthat/test-corpusQuery.R
+++ b/tests/testthat/test-corpusQuery.R
@@ -30,6 +30,28 @@
expect_gt(q@totalResults, 0)
})
+test_that("corpusQuery can handle latin1 encoded umlauts in query and vc", {
+ query <- "Ameisenb\xe4r"
+ Encoding(query)="latin1"
+ vc <- "pubPlace=N\xfcrnberg"
+ Encoding(vc)="latin1"
+
+ q <- new("KorAPConnection") %>%
+ corpusQuery(query, vc=vc)
+ expect_gt(q@totalResults, 0)
+})
+
+test_that("corpusQuery can handle utf8 encoded umlauts in query and vc", {
+ query <- "Ameisenb\xc3\xa4r"
+ Encoding(query)="UTF-8"
+ vc <- "pubPlace=N\xc3\xbcrnberg"
+ Encoding(vc)="UTF-8"
+
+ q <- new("KorAPConnection") %>%
+ corpusQuery(query, vc=vc)
+ expect_gt(q@totalResults, 0)
+})
+
test_that("fetchAll fetches all results", {
q <- new("KorAPConnection", verbose = TRUE) %>%
corpusQuery("Ameisenplage", vc = "pubDate since 2014")