Skip to content

Commit ebf709c

Browse files
committed
Fix R test cases for in-depth escaping scenario
1 parent b3a3ff7 commit ebf709c

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

src/targets/r/httr.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ module.exports = function (source, options) {
4141
code.push('queryString <- list(')
4242

4343
for (const query in qs) {
44+
const safeKey = query.match(/^[a-zA-Z][\w._]*$/)
45+
? query
46+
: '"' + escape(query) + '"'
47+
4448
if (count++ !== queryCount - 1) {
45-
code.push(' %s = "%s",', query, qs[query].toString())
49+
code.push(' %s = "%qd",', safeKey, qs[query].toString())
4650
} else {
47-
code.push(' %s = "%s"', query, qs[query].toString())
51+
code.push(' %s = "%qd"', safeKey, qs[query].toString())
4852
}
4953
}
5054

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
library(httr)
2+
3+
url <- "http://example.test/%27%22%60$(%(%%7B%7B%7B/0%s//"
4+
5+
queryString <- list(
6+
"'" = "squote-key-test",
7+
"squote-value-test" = "'",
8+
"\"" = "dquote-key-test",
9+
"dquote-value-test" = "\"",
10+
"`" = "backtick-key-test",
11+
"backtick-value-test" = "`",
12+
"$(" = "dollar-parenthesis-key-test",
13+
"dollar-parenthesis-value-test" = "$(",
14+
"#{" = "hash-brace-key-test",
15+
"hash-brace-value-test" = "#{",
16+
"%(" = "percent-parenthesis-key-test",
17+
"percent-parenthesis-value-test" = "%(",
18+
"%{" = "percent-brace-key-test",
19+
"percent-brace-value-test" = "%{",
20+
"{{" = "double-brace-key-test",
21+
"double-brace-value-test" = "{{",
22+
"\\0" = "null-key-test",
23+
"null-value-test" = "\\0",
24+
"%s" = "string-fmt-key-test",
25+
"string-fmt-value-test" = "%s",
26+
"\\" = "slash-key-test"
27+
"slash-value-test" = "\\",
28+
)
29+
30+
payload <- "' \" ` $( #{ %( %{ {{ \\0 %s \\"
31+
32+
encode <- "raw"
33+
34+
response <- VERB("POST", url, body = payload, query = queryString, add_headers(squote_value_test = '\'', dquote_value_test = '"', backtick_value_test = '`', dollar_parenthesis_value_test = '$(', hash_brace_value_test = '#{', percent_parenthesis_value_test = '%(', percent_brace_value_test = '%{', double_brace_value_test = '{{', null_value_test = '\\0', string_fmt_value_test = '%s', slash_value_test = '\\'), content_type("text/plain"), encode = encode)
35+
36+
content(response, "text")

test/fixtures/output/r/httr/nested.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ library(httr)
33
url <- "http://mockbin.com/har"
44

55
queryString <- list(
6-
foo[bar] = "baz,zap",
6+
"foo[bar]" = "baz,zap",
77
fiz = "buz"
88
)
99

test/targets.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ const skipMe = {
4444
clojure: {
4545
clj_http: ['jsonObj-null-value', 'jsonObj-multiline']
4646
},
47-
r: {
48-
httr: ['malicious']
49-
},
5047
'*': {
5148
'*': []
5249
}

0 commit comments

Comments
 (0)