json 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json might be problematic. Click here for more details.

data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 2006-08-25 (0.4.2)
2
+ * Fixed a bug in handling solidi (/-characters), that was reported by
3
+ Kevin Gilpin <kevin.gilpin@alum.mit.edu>.
1
4
  2006-02-06 (0.4.1)
2
5
  * Fixed a bug concerning escaping with backslashes. Thanks for the report go
3
6
  to Florian Munz <surf@theflow.de>.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ include Config
5
5
 
6
6
  PKG_NAME = 'json'
7
7
  PKG_VERSION = File.read('VERSION').chomp
8
- PKG_FILES = FileList["**/*"].exclude("CVS").exclude("pkg")
8
+ PKG_FILES = FileList["**/*"].exclude("CVS").exclude("pkg").exclude('coverage')
9
9
 
10
10
  desc "Installing library"
11
11
  task :install do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -140,12 +140,15 @@ module JSON
140
140
  end
141
141
 
142
142
  # Returns _true_ if JSON supports unicode, otherwise _false_ is returned.
143
+ #
144
+ # If loading of the iconv library fails, or it doesn't support utf8/utf16
145
+ # encoding, this will be set to false, as a fallback.
143
146
  def support_unicode?
144
147
  !!@support_unicode
145
148
  end
146
149
  end
147
- JSON.support_unicode = true # default, hower it's possible to switch off full
148
- # unicode support, if non-ascii bytes should be
150
+ JSON.support_unicode = true # default, however it's possible to switch off
151
+ # full unicode support, if non-ascii bytes should be
149
152
  # just passed through.
150
153
 
151
154
  begin
@@ -154,8 +157,59 @@ module JSON
154
157
  UTF16toUTF8 = Iconv.new('utf-8', 'utf-16be')
155
158
  # An iconv instance to convert from UTF16 Big Endian to UTF8.
156
159
  UTF8toUTF16 = Iconv.new('utf-16be', 'utf-8'); UTF8toUTF16.iconv('no bom')
160
+ rescue Errno::EINVAL
161
+ begin
162
+ old_verbose = $VERBOSE
163
+ $VERBOSE = nil
164
+ # An iconv instance to convert from UTF8 to UTF16 Big Endian.
165
+ UTF16toUTF8 = Iconv.new('utf-8', 'utf-16')
166
+ # An iconv instance to convert from UTF16 Big Endian to UTF8.
167
+ UTF8toUTF16 = Iconv.new('utf-16', 'utf-8'); UTF8toUTF16.iconv('no bom')
168
+ if UTF8toUTF16.iconv("\xe2\x82\xac") == "\xac\x20"
169
+ swapper = Class.new do
170
+ def initialize(iconv)
171
+ @iconv = iconv
172
+ end
173
+
174
+ def iconv(string)
175
+ result = @iconv.iconv(string)
176
+ JSON.swap!(result)
177
+ end
178
+ end
179
+ UTF8toUTF16 = swapper.new(UTF8toUTF16)
180
+ end
181
+ if UTF16toUTF8.iconv("\xac\x20") == "\xe2\x82\xac"
182
+ swapper = Class.new do
183
+ def initialize(iconv)
184
+ @iconv = iconv
185
+ end
186
+
187
+ def iconv(string)
188
+ string = JSON.swap!(string.dup)
189
+ @iconv.iconv(string)
190
+ end
191
+ end
192
+ UTF16toUTF8 = swapper.new(UTF16toUTF8)
193
+ end
194
+ rescue Errno::EINVAL
195
+ # Enforce disabling of unicode support, if iconv doesn't support
196
+ # UTF8/UTF16 at all.
197
+ JSON.support_unicode = false
198
+ ensure
199
+ $VERBOSE = old_verbose
200
+ end
157
201
  rescue LoadError
158
- JSON.support_unicode = false # enforce disabling of unicode support
202
+ # Enforce disabling of unicode support, if iconv doesn't exist.
203
+ JSON.support_unicode = false
204
+ end
205
+
206
+ # Swap consecutive bytes in string in place.
207
+ def self.swap!(string)
208
+ 0.upto(string.size / 2) do |i|
209
+ break unless string[2 * i + 1]
210
+ string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
211
+ end
212
+ string
159
213
  end
160
214
 
161
215
  # This class implements the JSON parser that is used to parse a JSON string
@@ -215,7 +269,7 @@ module JSON
215
269
  def parse_string
216
270
  if scan(STRING)
217
271
  return '' if self[1].empty?
218
- self[1].gsub(/\\(?:[\\bfnrt"]|u([A-Fa-f\d]{4}))/) do
272
+ self[1].gsub(%r(\\(?:[\\bfnrt"/]|u([A-Fa-f\d]{4})))) do
219
273
  case $~[0]
220
274
  when '\\\\' then '\\'
221
275
  when '\\b' then "\b"
@@ -224,6 +278,7 @@ module JSON
224
278
  when '\\r' then "\r"
225
279
  when '\\t' then "\t"
226
280
  when '\\"' then '"'
281
+ when '\\/' then '/'
227
282
  else
228
283
  if JSON.support_unicode? and $KCODE == 'UTF8'
229
284
  JSON.utf16_to_utf8($~[1])
@@ -408,6 +463,7 @@ module JSON
408
463
  when char == ?\r then result << '\r'
409
464
  when char == ?" then result << '\"'
410
465
  when char == ?\\ then result << '\\\\'
466
+ when char == ?/ then result << '\/'
411
467
  when char.between?(0x0, 0x1f) then result << "\\u%04x" % char
412
468
  when char.between?(0x20, 0x7f) then result << char
413
469
  when !(JSON.support_unicode? && $KCODE == 'UTF8')
@@ -5,7 +5,7 @@ require 'test/unit/testsuite'
5
5
  $:.unshift File.expand_path(File.dirname($0))
6
6
  $:.unshift 'lib'
7
7
  $:.unshift '../lib'
8
- #require 'coverage'
8
+ $:.unshift 'tests'
9
9
  require 'test_json'
10
10
 
11
11
  class TS_AllTests
@@ -104,18 +104,22 @@ class TC_JSON < Test::Unit::TestCase
104
104
  assert_equal '"\u001f"', 0x1f.chr.to_json
105
105
  assert_equal '" "', ' '.to_json
106
106
  assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json
107
- utf8 = '© ≠ €!'
108
- json = '"\u00a9 \u2260 \u20ac!"'
109
- assert_equal json, utf8.to_json
110
- assert_equal utf8, parse(json)
111
- utf8 = "\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"
112
- json = '"\u3042\u3044\u3046\u3048\u304a"'
113
- assert_equal json, utf8.to_json
114
- assert_equal utf8, parse(json)
115
- utf8 = 'საქართველო'
116
- json = '"\u10e1\u10d0\u10e5\u10d0\u10e0\u10d7\u10d5\u10d4\u10da\u10dd"'
117
- assert_equal json, utf8.to_json
118
- assert_equal utf8, parse(json)
107
+ if JSON.support_unicode?
108
+ utf8 = '© €!'
109
+ json = '"\u00a9 \u2260 \u20ac!"'
110
+ assert_equal json, utf8.to_json
111
+ assert_equal utf8, parse(json)
112
+ utf8 = "\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"
113
+ json = '"\u3042\u3044\u3046\u3048\u304a"'
114
+ assert_equal json, utf8.to_json
115
+ assert_equal utf8, parse(json)
116
+ utf8 = 'საქართველო'
117
+ json = '"\u10e1\u10d0\u10e5\u10d0\u10e0\u10d7\u10d5\u10d4\u10da\u10dd"'
118
+ assert_equal json, utf8.to_json
119
+ assert_equal utf8, parse(json)
120
+ else
121
+ warn "No unicode support found - skipping test"
122
+ end
119
123
  end
120
124
 
121
125
  def test_comments
@@ -187,6 +191,10 @@ EOT
187
191
  end
188
192
 
189
193
  def test_utf8_mode
194
+ unless JSON.support_unicode?
195
+ warn "No unicode support found - skipping test"
196
+ return
197
+ end
190
198
  $KCODE = 'NONE'
191
199
  utf8 = "© ≠ €! - \001"
192
200
  json = "\"© ≠ €! - \\u0001\""
@@ -213,6 +221,10 @@ EOT
213
221
  json = '"\\""'
214
222
  data = JSON.parse(json)
215
223
  assert_equal json, JSON.unparse(data)
224
+ json = '"\/"'
225
+ data = JSON.parse(json)
226
+ assert_equal '/', data
227
+ assert_equal json, JSON.unparse(data)
216
228
  end
217
229
  end
218
230
  # vim: set et sw=2 ts=2:
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: json
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.1
7
- date: 2006-02-06 00:00:00 +01:00
6
+ version: 0.4.2
7
+ date: 2006-08-25 00:00:00 +02:00
8
8
  summary: A JSON implementation in Ruby
9
9
  require_paths:
10
10
  - lib
@@ -29,33 +29,30 @@ authors:
29
29
  - Florian Frank
30
30
  files:
31
31
  - bin
32
- - install.rb
33
- - GPL
34
- - linecover_config.rb
35
- - TODO
36
- - Rakefile
37
- - linecover.db
38
32
  - VERSION
33
+ - TODO
39
34
  - tests
35
+ - GPL
36
+ - install.rb
37
+ - Rakefile
38
+ - lib
40
39
  - README
41
40
  - CHANGES
42
- - lib
43
41
  - bin/edit_json.rb
44
- - tests/load_linecover.rb
45
- - tests/test_json.rb
46
42
  - tests/runner.rb
47
- - lib/json.rb
43
+ - tests/test_json.rb
48
44
  - lib/json
49
- - lib/json/json.xpm
50
- - lib/json/NilClass.xpm
51
- - lib/json/Key.xpm
45
+ - lib/json.rb
52
46
  - lib/json/FalseClass.xpm
53
- - lib/json/editor.rb
54
- - lib/json/Array.xpm
55
47
  - lib/json/TrueClass.xpm
48
+ - lib/json/Hash.xpm
49
+ - lib/json/Key.xpm
56
50
  - lib/json/Numeric.xpm
51
+ - lib/json/Array.xpm
52
+ - lib/json/editor.rb
57
53
  - lib/json/String.xpm
58
- - lib/json/Hash.xpm
54
+ - lib/json/NilClass.xpm
55
+ - lib/json/json.xpm
59
56
  test_files:
60
57
  - tests/runner.rb
61
58
  rdoc_options: []
Binary file
@@ -1,14 +0,0 @@
1
- module LineCover::Config
2
- VERSION = 1
3
- COVERAGE_DATABASE = 'linecover.db'
4
- HTML_OUTPUT_DIRECTORY = 'linecover'
5
- CONSOLE_LAST_COLUMN = 80
6
- FILE_FILTER_ORDER = :EXCLUDE_INCLUDE
7
- FILE_FILTER_INCLUDE = [
8
- #%r(^(\./)?lib/.*\.rb$/),
9
- ]
10
- FILE_FILTER_EXCLUDE = [
11
- %r(^/.*),
12
- %r(^(\./)?test(s)?/.*\.rb$),
13
- ]
14
- end
@@ -1,6 +0,0 @@
1
- begin
2
- require 'linecover'
3
- rescue LoadError
4
- require 'rubygems'
5
- require 'linecover'
6
- end