json_pure 1.7.1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  .*.sw[pon]
2
2
  coverage
3
+ tags
3
4
  pkg
4
5
  .nfs.*
5
6
  .idea
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 2012-05-11 (1.7.2)
2
+ * Fix some encoding issues, that cause problems for the pure and the
3
+ extension variant in jruby 1.9 mode.
1
4
  2012-04-28 (1.7.1)
2
5
  * Some small fixes for building
3
6
  2012-04-28 (1.7.0)
data/Rakefile CHANGED
@@ -343,6 +343,11 @@ else
343
343
  rm_rf EXT_PARSER_SRC
344
344
  end
345
345
 
346
+ desc "Update the tags file"
347
+ task :tags do
348
+ system 'ctags', *Dir['**/*.{rb,c,h,java}']
349
+ end
350
+
346
351
  file EXT_PARSER_SRC => RAGEL_PATH do
347
352
  cd EXT_PARSER_DIR do
348
353
  if RAGEL_CODEGEN == 'ragel'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.7.1
1
+ 1.7.2
@@ -167,9 +167,16 @@ public final class Generator {
167
167
  }
168
168
 
169
169
  RubyString generateNew(Session session, T object) {
170
+ RubyString result;
170
171
  ByteList buffer = new ByteList(guessSize(session, object));
171
172
  generate(session, object, buffer);
172
- return RubyString.newString(session.getRuntime(), buffer);
173
+ result = RubyString.newString(session.getRuntime(), buffer);
174
+ ThreadContext context = session.getContext();
175
+ RuntimeInfo info = session.getInfo();
176
+ if (info.encodingsSupported()) {
177
+ result.force_encoding(context, info.utf8.get());
178
+ }
179
+ return result;
173
180
  }
174
181
 
175
182
  abstract void generate(Session session, T object, ByteList buffer);
@@ -212,6 +212,10 @@ public class GeneratorState extends RubyObject {
212
212
  throw Utils.newException(context, Utils.M_GENERATOR_ERROR,
213
213
  "only generation of JSON objects or arrays allowed");
214
214
  }
215
+ RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
216
+ if (info.encodingsSupported()) {
217
+ result.force_encoding(context, info.utf8.get());
218
+ }
215
219
  return result;
216
220
  }
217
221
 
@@ -1477,6 +1477,10 @@ case 5:
1477
1477
  }
1478
1478
 
1479
1479
  if (cs >= JSON_string_first_final && result != null) {
1480
+ RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
1481
+ if (info.encodingsSupported() && result instanceof RubyString) {
1482
+ ((RubyString)result).force_encoding(context, info.utf8.get());
1483
+ }
1480
1484
  res.update(result, p + 1);
1481
1485
  } else {
1482
1486
  res.update(null, p + 1);
@@ -1484,7 +1488,7 @@ case 5:
1484
1488
  }
1485
1489
 
1486
1490
 
1487
- // line 1488 "Parser.java"
1491
+ // line 1492 "Parser.java"
1488
1492
  private static byte[] init__JSON_array_actions_0()
1489
1493
  {
1490
1494
  return new byte [] {
@@ -1597,7 +1601,7 @@ static final int JSON_array_error = 0;
1597
1601
  static final int JSON_array_en_main = 1;
1598
1602
 
1599
1603
 
1600
- // line 693 "Parser.rl"
1604
+ // line 697 "Parser.rl"
1601
1605
 
1602
1606
 
1603
1607
  void parseArray(ParserResult res, int p, int pe) {
@@ -1617,14 +1621,14 @@ static final int JSON_array_en_main = 1;
1617
1621
  }
1618
1622
 
1619
1623
 
1620
- // line 1623 "Parser.java"
1624
+ // line 1625 "Parser.java"
1621
1625
  {
1622
1626
  cs = JSON_array_start;
1623
1627
  }
1624
1628
 
1625
- // line 714 "Parser.rl"
1629
+ // line 716 "Parser.rl"
1626
1630
 
1627
- // line 1630 "Parser.java"
1631
+ // line 1632 "Parser.java"
1628
1632
  {
1629
1633
  int _klen;
1630
1634
  int _trans = 0;
@@ -1705,7 +1709,7 @@ case 1:
1705
1709
  switch ( _JSON_array_actions[_acts++] )
1706
1710
  {
1707
1711
  case 0:
1708
- // line 662 "Parser.rl"
1712
+ // line 666 "Parser.rl"
1709
1713
  {
1710
1714
  parseValue(res, p, pe);
1711
1715
  if (res.result == null) {
@@ -1722,13 +1726,13 @@ case 1:
1722
1726
  }
1723
1727
  break;
1724
1728
  case 1:
1725
- // line 677 "Parser.rl"
1729
+ // line 681 "Parser.rl"
1726
1730
  {
1727
1731
  p--;
1728
1732
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
1729
1733
  }
1730
1734
  break;
1731
- // line 1734 "Parser.java"
1735
+ // line 1736 "Parser.java"
1732
1736
  }
1733
1737
  }
1734
1738
  }
@@ -1748,7 +1752,7 @@ case 5:
1748
1752
  break; }
1749
1753
  }
1750
1754
 
1751
- // line 715 "Parser.rl"
1755
+ // line 717 "Parser.rl"
1752
1756
 
1753
1757
  if (cs >= JSON_array_first_final) {
1754
1758
  res.update(result, p + 1);
@@ -1758,7 +1762,7 @@ case 5:
1758
1762
  }
1759
1763
 
1760
1764
 
1761
- // line 1764 "Parser.java"
1765
+ // line 1766 "Parser.java"
1762
1766
  private static byte[] init__JSON_object_actions_0()
1763
1767
  {
1764
1768
  return new byte [] {
@@ -1881,7 +1885,7 @@ static final int JSON_object_error = 0;
1881
1885
  static final int JSON_object_en_main = 1;
1882
1886
 
1883
1887
 
1884
- // line 774 "Parser.rl"
1888
+ // line 776 "Parser.rl"
1885
1889
 
1886
1890
 
1887
1891
  void parseObject(ParserResult res, int p, int pe) {
@@ -1906,14 +1910,14 @@ static final int JSON_object_en_main = 1;
1906
1910
  }
1907
1911
 
1908
1912
 
1909
- // line 1912 "Parser.java"
1913
+ // line 1914 "Parser.java"
1910
1914
  {
1911
1915
  cs = JSON_object_start;
1912
1916
  }
1913
1917
 
1914
- // line 798 "Parser.rl"
1918
+ // line 800 "Parser.rl"
1915
1919
 
1916
- // line 1919 "Parser.java"
1920
+ // line 1921 "Parser.java"
1917
1921
  {
1918
1922
  int _klen;
1919
1923
  int _trans = 0;
@@ -1994,7 +1998,7 @@ case 1:
1994
1998
  switch ( _JSON_object_actions[_acts++] )
1995
1999
  {
1996
2000
  case 0:
1997
- // line 729 "Parser.rl"
2001
+ // line 731 "Parser.rl"
1998
2002
  {
1999
2003
  parseValue(res, p, pe);
2000
2004
  if (res.result == null) {
@@ -2011,7 +2015,7 @@ case 1:
2011
2015
  }
2012
2016
  break;
2013
2017
  case 1:
2014
- // line 744 "Parser.rl"
2018
+ // line 746 "Parser.rl"
2015
2019
  {
2016
2020
  parseString(res, p, pe);
2017
2021
  if (res.result == null) {
@@ -2031,13 +2035,13 @@ case 1:
2031
2035
  }
2032
2036
  break;
2033
2037
  case 2:
2034
- // line 762 "Parser.rl"
2038
+ // line 764 "Parser.rl"
2035
2039
  {
2036
2040
  p--;
2037
2041
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
2038
2042
  }
2039
2043
  break;
2040
- // line 2043 "Parser.java"
2044
+ // line 2045 "Parser.java"
2041
2045
  }
2042
2046
  }
2043
2047
  }
@@ -2057,7 +2061,7 @@ case 5:
2057
2061
  break; }
2058
2062
  }
2059
2063
 
2060
- // line 799 "Parser.rl"
2064
+ // line 801 "Parser.rl"
2061
2065
 
2062
2066
  if (cs < JSON_object_first_final) {
2063
2067
  res.update(null, p + 1);
@@ -2090,7 +2094,7 @@ case 5:
2090
2094
  }
2091
2095
 
2092
2096
 
2093
- // line 2096 "Parser.java"
2097
+ // line 2098 "Parser.java"
2094
2098
  private static byte[] init__JSON_actions_0()
2095
2099
  {
2096
2100
  return new byte [] {
@@ -2194,7 +2198,7 @@ static final int JSON_error = 0;
2194
2198
  static final int JSON_en_main = 1;
2195
2199
 
2196
2200
 
2197
- // line 864 "Parser.rl"
2201
+ // line 866 "Parser.rl"
2198
2202
 
2199
2203
 
2200
2204
  public IRubyObject parseStrict() {
@@ -2204,16 +2208,16 @@ static final int JSON_en_main = 1;
2204
2208
  ParserResult res = new ParserResult();
2205
2209
 
2206
2210
 
2207
- // line 2210 "Parser.java"
2211
+ // line 2212 "Parser.java"
2208
2212
  {
2209
2213
  cs = JSON_start;
2210
2214
  }
2211
2215
 
2212
- // line 873 "Parser.rl"
2216
+ // line 875 "Parser.rl"
2213
2217
  p = byteList.begin();
2214
2218
  pe = p + byteList.length();
2215
2219
 
2216
- // line 2219 "Parser.java"
2220
+ // line 2221 "Parser.java"
2217
2221
  {
2218
2222
  int _klen;
2219
2223
  int _trans = 0;
@@ -2294,7 +2298,7 @@ case 1:
2294
2298
  switch ( _JSON_actions[_acts++] )
2295
2299
  {
2296
2300
  case 0:
2297
- // line 836 "Parser.rl"
2301
+ // line 838 "Parser.rl"
2298
2302
  {
2299
2303
  currentNesting = 1;
2300
2304
  parseObject(res, p, pe);
@@ -2308,7 +2312,7 @@ case 1:
2308
2312
  }
2309
2313
  break;
2310
2314
  case 1:
2311
- // line 848 "Parser.rl"
2315
+ // line 850 "Parser.rl"
2312
2316
  {
2313
2317
  currentNesting = 1;
2314
2318
  parseArray(res, p, pe);
@@ -2321,7 +2325,7 @@ case 1:
2321
2325
  }
2322
2326
  }
2323
2327
  break;
2324
- // line 2327 "Parser.java"
2328
+ // line 2329 "Parser.java"
2325
2329
  }
2326
2330
  }
2327
2331
  }
@@ -2341,7 +2345,7 @@ case 5:
2341
2345
  break; }
2342
2346
  }
2343
2347
 
2344
- // line 876 "Parser.rl"
2348
+ // line 878 "Parser.rl"
2345
2349
 
2346
2350
  if (cs >= JSON_first_final && p == pe) {
2347
2351
  return result;
@@ -2351,7 +2355,7 @@ case 5:
2351
2355
  }
2352
2356
 
2353
2357
 
2354
- // line 2357 "Parser.java"
2358
+ // line 2359 "Parser.java"
2355
2359
  private static byte[] init__JSON_quirks_mode_actions_0()
2356
2360
  {
2357
2361
  return new byte [] {
@@ -2454,7 +2458,7 @@ static final int JSON_quirks_mode_error = 0;
2454
2458
  static final int JSON_quirks_mode_en_main = 1;
2455
2459
 
2456
2460
 
2457
- // line 904 "Parser.rl"
2461
+ // line 906 "Parser.rl"
2458
2462
 
2459
2463
 
2460
2464
  public IRubyObject parseQuirksMode() {
@@ -2464,16 +2468,16 @@ static final int JSON_quirks_mode_en_main = 1;
2464
2468
  ParserResult res = new ParserResult();
2465
2469
 
2466
2470
 
2467
- // line 2470 "Parser.java"
2471
+ // line 2472 "Parser.java"
2468
2472
  {
2469
2473
  cs = JSON_quirks_mode_start;
2470
2474
  }
2471
2475
 
2472
- // line 913 "Parser.rl"
2476
+ // line 915 "Parser.rl"
2473
2477
  p = byteList.begin();
2474
2478
  pe = p + byteList.length();
2475
2479
 
2476
- // line 2479 "Parser.java"
2480
+ // line 2481 "Parser.java"
2477
2481
  {
2478
2482
  int _klen;
2479
2483
  int _trans = 0;
@@ -2554,7 +2558,7 @@ case 1:
2554
2558
  switch ( _JSON_quirks_mode_actions[_acts++] )
2555
2559
  {
2556
2560
  case 0:
2557
- // line 890 "Parser.rl"
2561
+ // line 892 "Parser.rl"
2558
2562
  {
2559
2563
  parseValue(res, p, pe);
2560
2564
  if (res.result == null) {
@@ -2566,7 +2570,7 @@ case 1:
2566
2570
  }
2567
2571
  }
2568
2572
  break;
2569
- // line 2572 "Parser.java"
2573
+ // line 2574 "Parser.java"
2570
2574
  }
2571
2575
  }
2572
2576
  }
@@ -2586,7 +2590,7 @@ case 5:
2586
2590
  break; }
2587
2591
  }
2588
2592
 
2589
- // line 916 "Parser.rl"
2593
+ // line 918 "Parser.rl"
2590
2594
 
2591
2595
  if (cs >= JSON_quirks_mode_first_final && p == pe) {
2592
2596
  return result;
@@ -647,6 +647,10 @@ public class Parser extends RubyObject {
647
647
  }
648
648
 
649
649
  if (cs >= JSON_string_first_final && result != null) {
650
+ RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
651
+ if (info.encodingsSupported() && result instanceof RubyString) {
652
+ ((RubyString)result).force_encoding(context, info.utf8.get());
653
+ }
650
654
  res.update(result, p + 1);
651
655
  } else {
652
656
  res.update(null, p + 1);
data/json.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "json"
5
- s.version = "1.7.1"
5
+ s.version = "1.7.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Florian Frank"]
9
- s.date = "2012-05-07"
9
+ s.date = "2012-05-11"
10
10
  s.description = "This is a JSON implementation as a Ruby extension in C."
11
11
  s.email = "flori@ping.de"
12
12
  s.extensions = ["ext/json/ext/parser/extconf.rb", "ext/json/ext/generator/extconf.rb"]
data/json_pure.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "json_pure"
5
- s.version = "1.7.1"
5
+ s.version = "1.7.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Florian Frank"]
9
- s.date = "2012-05-07"
9
+ s.date = "2012-05-11"
10
10
  s.description = "This is a JSON implementation in pure Ruby."
11
11
  s.email = "flori@ping.de"
12
12
  s.extra_rdoc_files = ["README.rdoc"]
data/lib/json/add/time.rb CHANGED
@@ -20,10 +20,13 @@ class Time
20
20
  # Returns a hash, that will be turned into a JSON object and represent this
21
21
  # object.
22
22
  def as_json(*)
23
+ nanoseconds = [ tv_usec * 1000 ]
24
+ respond_to?(:tv_nsec) and nanoseconds << tv_nsec
25
+ nanoseconds = nanoseconds.max
23
26
  {
24
27
  JSON.create_id => self.class.name,
25
28
  's' => tv_sec,
26
- 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
29
+ 'n' => nanoseconds,
27
30
  }
28
31
  end
29
32
 
data/lib/json/common.rb CHANGED
@@ -103,7 +103,13 @@ module JSON
103
103
  MinusInfinity = -Infinity
104
104
 
105
105
  # The base exception for JSON errors.
106
- class JSONError < StandardError; end
106
+ class JSONError < StandardError
107
+ def self.wrap(exception)
108
+ obj = new("Wrapped(#{exception.class}): #{exception.message.inspect}")
109
+ obj.set_backtrace exception.backtrace
110
+ obj
111
+ end
112
+ end
107
113
 
108
114
  # This exception is raised if a parser error occurs.
109
115
  class ParserError < JSONError; end
@@ -41,7 +41,6 @@ module JSON
41
41
  if defined?(::Encoding)
42
42
  def utf8_to_json(string) # :nodoc:
43
43
  string = string.dup
44
- string << '' # XXX workaround: avoid buffer sharing
45
44
  string.force_encoding(::Encoding::ASCII_8BIT)
46
45
  string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] }
47
46
  string.force_encoding(::Encoding::UTF_8)
@@ -50,9 +49,8 @@ module JSON
50
49
 
51
50
  def utf8_to_json_ascii(string) # :nodoc:
52
51
  string = string.dup
53
- string << '' # XXX workaround: avoid buffer sharing
54
52
  string.force_encoding(::Encoding::ASCII_8BIT)
55
- string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] }
53
+ string.gsub!(/["\\\x0-\x1f]/n) { MAP[$&] }
56
54
  string.gsub!(/(
57
55
  (?:
58
56
  [\xc2-\xdf][\x80-\xbf] |
@@ -63,16 +61,18 @@ module JSON
63
61
  )/nx) { |c|
64
62
  c.size == 1 and raise GeneratorError, "invalid utf8 byte: '#{c}'"
65
63
  s = JSON.iconv('utf-16be', 'utf-8', c).unpack('H*')[0]
64
+ s.force_encoding(::Encoding::ASCII_8BIT)
66
65
  s.gsub!(/.{4}/n, '\\\\u\&')
66
+ s.force_encoding(::Encoding::UTF_8)
67
67
  }
68
68
  string.force_encoding(::Encoding::UTF_8)
69
69
  string
70
70
  rescue => e
71
- raise GeneratorError, "Caught #{e.class}: #{e}"
71
+ raise GeneratorError.wrap(e)
72
72
  end
73
73
  else
74
74
  def utf8_to_json(string) # :nodoc:
75
- string.gsub(/["\\\x0-\x1f]/) { MAP[$&] }
75
+ string.gsub(/["\\\x0-\x1f]/n) { MAP[$&] }
76
76
  end
77
77
 
78
78
  def utf8_to_json_ascii(string) # :nodoc:
@@ -91,7 +91,7 @@ module JSON
91
91
  }
92
92
  string
93
93
  rescue => e
94
- raise GeneratorError, "Caught #{e.class}: #{e}"
94
+ raise GeneratorError.wrap(e)
95
95
  end
96
96
  end
97
97
  module_function :utf8_to_json, :utf8_to_json_ascii
data/lib/json/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.7.1'
3
+ VERSION = '1.7.2'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_pure
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-07 00:00:00.000000000 Z
12
+ date: 2012-05-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: permutation
@@ -199,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
199
  version: '0'
200
200
  segments:
201
201
  - 0
202
- hash: 2493515216369653026
202
+ hash: 3438040522195116142
203
203
  required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  none: false
205
205
  requirements: