yajl-ruby 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5006e05689ab5c95a3e4dd98b03c66a7bb46394c
4
- data.tar.gz: ecfd90a4a8993aa166c0f2b0b983dc05bfa96e51
3
+ metadata.gz: c99601133192fb2ea1f0586ac1b4a83dc465d9a8
4
+ data.tar.gz: cbfce4619e6c2ccd5b761bf8d6005dbee6ce043e
5
5
  SHA512:
6
- metadata.gz: 9e21e2069c984380ce506562aa837b4e02207e3368085b7cbf651dd2075de0c4d0ec43e1e1006abcaa947c797b2ec6a59bba7c73bea17ae9b47e1f01b3552dbb
7
- data.tar.gz: 01df11ba7ab076382eb270e692bb316f2d5ab06034275661f65ff58888a89d1ffed25d2a4081bd9cad9c8a0275eaa8c23411528d2ca9a3423a83e9bba59b2d57
6
+ metadata.gz: 78c816a3a6368d3b0520d27b5987da10a40478357424e305aa121a6359141ef51c8ee9a3caa4bc3dde159156d5cb6f9af6d5cfd3c576c543b5fd9178ad2993e6
7
+ data.tar.gz: fc968516c955984c03c184d11a349c82c109adcce8c590a7537bd291a315bb2a8ac0be92ae927b9458e10dee07b564ebf15806bc591b89b0d09df89b5d6ce173
@@ -59,12 +59,18 @@ yajl_string_encode2(const yajl_print_t print,
59
59
  unsigned int htmlSafe)
60
60
  {
61
61
  unsigned int beg = 0;
62
- unsigned int end = 0;
62
+ unsigned int end = 0;
63
+ unsigned int increment = 0;
63
64
  char hexBuf[7];
65
+ char entityBuffer[7];
64
66
  hexBuf[0] = '\\'; hexBuf[1] = 'u'; hexBuf[2] = '0'; hexBuf[3] = '0';
65
67
  hexBuf[6] = 0;
66
68
 
69
+ entityBuffer[0] = '\\'; entityBuffer[1] = 'u'; entityBuffer[2] = '2'; entityBuffer[3] = '0';
70
+ entityBuffer[6] = 0;
71
+
67
72
  while (end < len) {
73
+ increment = 1;
68
74
  const char * escaped = NULL;
69
75
  switch (str[end]) {
70
76
  case '\r': escaped = "\\r"; break;
@@ -76,10 +82,39 @@ yajl_string_encode2(const yajl_print_t print,
76
82
  case '\b': escaped = "\\b"; break;
77
83
  case '\t': escaped = "\\t"; break;
78
84
  case '/':
79
- if (htmlSafe) {
85
+ if (htmlSafe == 1 || htmlSafe == 2) {
80
86
  escaped = "\\/";
81
87
  }
82
88
  break;
89
+ /* Escaping 0xe280a8 0xe280a9 */
90
+ case 0xe2:
91
+ if (htmlSafe == 2) {
92
+ if (len - end >= 2 && str[end + 1] == 0x80) {
93
+ if (str[end + 2] == 0xa8) {
94
+ increment = 3;
95
+ entityBuffer[4] = '2';
96
+ entityBuffer[5] = '8';
97
+ escaped = entityBuffer;
98
+ break;
99
+ }
100
+
101
+ if (str[end + 2] == 0xa9) {
102
+ increment = 3;
103
+ entityBuffer[4] = '2';
104
+ entityBuffer[5] = '9';
105
+ escaped = entityBuffer;
106
+ break;
107
+ }
108
+ }
109
+ }
110
+ case '<':
111
+ case '>':
112
+ case '&':
113
+ if (htmlSafe == 2) {
114
+ CharToHex(str[end], hexBuf + 4);
115
+ escaped = hexBuf;
116
+ }
117
+ break;
83
118
  default:
84
119
  if ((unsigned char) str[end] < 32) {
85
120
  CharToHex(str[end], hexBuf + 4);
@@ -90,7 +125,8 @@ yajl_string_encode2(const yajl_print_t print,
90
125
  if (escaped != NULL) {
91
126
  print(ctx, (const char *) (str + beg), end - beg);
92
127
  print(ctx, escaped, (unsigned int)strlen(escaped));
93
- beg = ++end;
128
+ end += increment;
129
+ beg = end;
94
130
  } else {
95
131
  ++end;
96
132
  }
@@ -1030,9 +1030,14 @@ static VALUE rb_yajl_encoder_new(int argc, VALUE * argv, VALUE klass) {
1030
1030
  actualIndent = indentString;
1031
1031
  }
1032
1032
  }
1033
+
1033
1034
  if (rb_hash_aref(opts, sym_html_safe) == Qtrue) {
1034
1035
  htmlSafe = 1;
1035
1036
  }
1037
+
1038
+ if (rb_hash_aref(opts, sym_entities) == Qtrue) {
1039
+ htmlSafe = 2;
1040
+ }
1036
1041
  }
1037
1042
  if (!indentString) {
1038
1043
  indentString = defaultIndentString;
@@ -1356,6 +1361,7 @@ void Init_yajl() {
1356
1361
  sym_pretty = ID2SYM(rb_intern("pretty"));
1357
1362
  sym_indent = ID2SYM(rb_intern("indent"));
1358
1363
  sym_html_safe = ID2SYM(rb_intern("html_safe"));
1364
+ sym_entities = ID2SYM(rb_intern("entities"));
1359
1365
  sym_terminator = ID2SYM(rb_intern("terminator"));
1360
1366
  sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
1361
1367
  sym_symbolize_names = ID2SYM(rb_intern("symbolize_names"));
@@ -56,7 +56,7 @@ static rb_encoding *utf8Encoding;
56
56
  static VALUE cStandardError, cParseError, cEncodeError, mYajl, cParser, cProjector, cEncoder;
57
57
  static ID intern_io_read, intern_call, intern_keys, intern_to_s,
58
58
  intern_to_json, intern_has_key, intern_to_sym, intern_as_json;
59
- static ID sym_allow_comments, sym_check_utf8, sym_pretty, sym_indent, sym_terminator, sym_symbolize_keys, sym_symbolize_names, sym_html_safe;
59
+ static ID sym_allow_comments, sym_check_utf8, sym_pretty, sym_indent, sym_terminator, sym_symbolize_keys, sym_symbolize_names, sym_html_safe, sym_entities;
60
60
 
61
61
  #define GetParser(obj, sval) Data_Get_Struct(obj, yajl_parser_wrapper, sval);
62
62
  #define GetEncoder(obj, sval) Data_Get_Struct(obj, yajl_encoder_wrapper, sval);
@@ -1,3 +1,3 @@
1
1
  module Yajl
2
- VERSION = '1.4.0'
2
+ VERSION = '1.4.1'
3
3
  end
@@ -275,11 +275,27 @@ describe "Yajl JSON encoder" do
275
275
  expect(safe_encoder.encode("</script>")).to eql("\"<\\/script>\"")
276
276
  end
277
277
 
278
+ it "should not encode characters with entities by default" do
279
+ expect(Yajl.dump("\u2028\u2029><&")).to eql("\"\u2028\u2029><&\"")
280
+ end
281
+
282
+ it "should encode characters with entities when enabled" do
283
+ expect(Yajl.dump("\u2028\u2029><&", entities: true)).to eql("\"\\u2028\\u2029\\u003E\\u003C\\u0026\"")
284
+ end
285
+
278
286
  it "should default to *not* escaping / characters" do
279
287
  unsafe_encoder = Yajl::Encoder.new
280
288
  expect(unsafe_encoder.encode("</script>")).not_to eql("\"<\\/script>\"")
281
289
  end
282
290
 
291
+ it "should encode slashes when enabled" do
292
+ unsafe_encoder = Yajl::Encoder.new(:entities => false)
293
+ safe_encoder = Yajl::Encoder.new(:entities => true)
294
+
295
+ expect(unsafe_encoder.encode("</script>")).not_to eql("\"<\\/script>\"")
296
+ expect(safe_encoder.encode("</script>")).to eql("\"\\u003C\\/script\\u003E\"")
297
+ end
298
+
283
299
  it "return value of #to_json must be a string" do
284
300
  expect {
285
301
  Yajl::Encoder.encode(TheMindKiller.new)
@@ -17,11 +17,10 @@ Gem::Specification.new do |s|
17
17
  s.required_ruby_version = ">= 1.8.6"
18
18
 
19
19
  # tests
20
- s.add_development_dependency 'rake-compiler', '>= 0.7.5'
21
- s.add_development_dependency 'rspec', '~> 3.0'
20
+ s.add_development_dependency 'rake-compiler'
21
+ s.add_development_dependency 'rspec'
22
22
  # benchmarks
23
- s.add_development_dependency 'activesupport', '~> 3.1.2'
23
+ s.add_development_dependency 'activesupport'
24
24
  s.add_development_dependency 'json'
25
- s.add_development_dependency "benchmark-memory", "~> 0.1"
25
+ s.add_development_dependency "benchmark-memory"
26
26
  end
27
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yajl-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lopez
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-04-27 00:00:00.000000000 Z
12
+ date: 2018-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
@@ -17,42 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 0.7.5
20
+ version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 0.7.5
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '3.0'
34
+ version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '3.0'
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: activesupport
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 3.1.2
48
+ version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 3.1.2
55
+ version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: json
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -71,16 +71,16 @@ dependencies:
71
71
  name: benchmark-memory
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '0.1'
76
+ version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '0.1'
83
+ version: '0'
84
84
  description:
85
85
  email: seniorlopez@gmail.com
86
86
  executables: []