Skip to content

Commit

Permalink
fix: issue where query strings in R wouldn't be properly concatenated (
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored May 27, 2022
1 parent 3f108de commit 853374c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions __tests__/__fixtures__/output/r/httr/query-encoded.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ library(httr)
url <- "https://httpbin.org/anything"

queryString <- list(
startTime = "2019-06-13T19%3A08%3A25.455Z"
endTime = "2015-09-15T14%3A00%3A12-04%3A00",
startTime = "2019-06-13T19%3A08%3A25.455Z",
endTime = "2015-09-15T14%3A00%3A12-04%3A00"
)

response <- VERB("GET", url, query = queryString, content_type("application/octet-stream"))
Expand Down
13 changes: 5 additions & 8 deletions src/targets/r/httr.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@ module.exports = function (source) {

// Construct query string
const qs = source.queryObj;
const queryCount = Object.keys(qs).length;
// eslint-disable-next-line no-param-reassign
delete source.queryObj.key;

if (source.queryString.length === 1) {
const queryCount = Object.keys(qs).length;
if (queryCount === 1) {
code.push('queryString <- list(%s = "%s")', Object.keys(qs), Object.values(qs).toString()).blank();
} else if (source.queryString.length > 1) {
let count = 1;

} else if (queryCount > 1) {
code.push('queryString <- list(');

Object.keys(qs).forEach(query => {
// eslint-disable-next-line no-plusplus
if (count++ !== queryCount - 1) {
Object.keys(qs).forEach((query, i) => {
if (i !== queryCount - 1) {
code.push(' %s = "%s",', query, qs[query].toString());
} else {
code.push(' %s = "%s"', query, qs[query].toString());
Expand Down

0 comments on commit 853374c

Please sign in to comment.