curl_escape 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/curl_escape/curl_escape.c +35 -16
- data/lib/curl_escape/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55be49ada64c12d1e7d0bbd158f564503728a235
|
4
|
+
data.tar.gz: 9017ed915571561a448339e296634ed9b5c8c824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 721f4544d8503376390464694b7e98b8184249e63e4975c8ce322285f6c150db4c0e8bbe0b0ce3c43948358f5340667919d6b81a70d24c87c75588eaff62eba8
|
7
|
+
data.tar.gz: 7031c858e2c48907ef19fcb7bf487f801dd586a44c82a60ef187d46848df4802b031eb9b2c30fbdb33a8e8be10e1a075ffc8e84ff9916243cdf323b0e5d85ef4
|
@@ -3,47 +3,66 @@
|
|
3
3
|
#include <ruby.h>
|
4
4
|
#include <ruby/encoding.h>
|
5
5
|
|
6
|
+
char *alloc_output_buffer(char *cOutput);
|
7
|
+
|
6
8
|
VALUE ruby_curl_escape(VALUE self, VALUE str) {
|
7
|
-
int cnt;
|
9
|
+
int cnt, pos;
|
10
|
+
char c;
|
11
|
+
char *cStr, *cOutput, *buf;
|
12
|
+
char escaped_tilde[3] = "%7E";
|
8
13
|
VALUE output;
|
14
|
+
rb_encoding *enc;
|
9
15
|
|
10
16
|
static CURL *curl;
|
11
17
|
if (!curl) {
|
12
18
|
curl = curl_easy_init();
|
13
19
|
}
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
int pos = 0;
|
19
|
-
char buf[strlen(cOutput) * 3];
|
21
|
+
cStr = StringValueCStr(str);
|
22
|
+
cOutput = curl_easy_escape(curl, cStr, strlen(cStr));
|
20
23
|
|
24
|
+
pos = 0;
|
25
|
+
buf = alloc_output_buffer(cOutput);
|
21
26
|
if (cOutput) {
|
22
|
-
for (cnt = 0; *(cOutput + cnt) != '\0'; cnt++) {
|
23
|
-
if (
|
27
|
+
for (cnt = 0; (c = *(cOutput + cnt)) != '\0'; cnt++) {
|
28
|
+
if (c == '~') {
|
29
|
+
memcpy(buf + pos, escaped_tilde, 3);
|
30
|
+
pos += 2;
|
31
|
+
} else if (c != '%') {
|
32
|
+
buf[pos] = c;
|
33
|
+
} else if (strncmp(cOutput + cnt, "%20", 3) == 0) {
|
24
34
|
buf[pos] = '+';
|
25
35
|
cnt += 2;
|
26
|
-
} else if (*(cOutput + cnt) == '~') {
|
27
|
-
buf[pos] = '%';
|
28
|
-
buf[pos+1] = '7';
|
29
|
-
buf[pos+2] = 'E';
|
30
|
-
pos += 2;
|
31
36
|
} else {
|
32
|
-
buf[pos] =
|
37
|
+
buf[pos] = c;
|
33
38
|
}
|
34
39
|
pos++;
|
35
40
|
}
|
36
|
-
buf[pos
|
41
|
+
buf[pos] = '\0';
|
37
42
|
|
38
|
-
|
43
|
+
enc = rb_enc_get(str);
|
39
44
|
output = rb_enc_str_new_cstr(buf, enc);
|
40
45
|
curl_free(cOutput);
|
46
|
+
free(buf);
|
41
47
|
return output;
|
42
48
|
} else {
|
43
49
|
return Qnil;
|
44
50
|
}
|
45
51
|
}
|
46
52
|
|
53
|
+
char *alloc_output_buffer(char *cOutput) {
|
54
|
+
int i, tilde_cnt;
|
55
|
+
char *buf;
|
56
|
+
tilde_cnt = 0;
|
57
|
+
for (i = 0; *(cOutput + i) != '\0'; i++) {
|
58
|
+
if (*(cOutput + i) == '~') {
|
59
|
+
tilde_cnt++;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
buf = (char *)malloc(i + tilde_cnt * 2);
|
63
|
+
return buf;
|
64
|
+
}
|
65
|
+
|
47
66
|
void Init_curl_escape(void) {
|
48
67
|
VALUE module = rb_define_module("CurlEscape");
|
49
68
|
rb_define_singleton_method(module, "escape", ruby_curl_escape, 1);
|
data/lib/curl_escape/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curl_escape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|