qqwry 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # QQWry
2
2
 
3
- A Ruby interface for QQWry IP database.
3
+ A Ruby interface to QQWry IP database.
4
4
 
5
5
  ## Installation
6
6
 
data/lib/qqwry/record.rb CHANGED
@@ -37,7 +37,7 @@ module QQWry
37
37
  parse_area(file)
38
38
  end
39
39
  if @country
40
- @country = Iconv.conv('UTF-8', 'GBK', @country)
40
+ @country = conv(@country)
41
41
  @country = nil if @country=~ /\s*CZ88\.NET\s*/
42
42
  end
43
43
  end
@@ -56,6 +56,15 @@ module QQWry
56
56
  [ip].pack('N').unpack('C4').join('.')
57
57
  end
58
58
 
59
+ def conv(str)
60
+ begin
61
+ Iconv::conv('UTF-8', 'GBK', str)
62
+ rescue
63
+ str = str[0, str.length - 1]
64
+ retry
65
+ end
66
+ end
67
+
59
68
  def parse_area(file)
60
69
  case BinData::Uint8.read(file).to_i
61
70
  when 0x1, 0x2
@@ -69,7 +78,7 @@ module QQWry
69
78
  @area = BinData::Stringz.read(file).to_s
70
79
  end
71
80
  if @area
72
- @area = Iconv.conv('UTF-8', 'GBK', @area)
81
+ @area = conv(@area)
73
82
  # CZ88.NET is an advertisement
74
83
  @area = nil if @area =~ /\s*CZ88\.NET\s*/
75
84
  end
data/lib/qqwry/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module QQWry
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
data/qqwry.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = QQWry::VERSION
9
9
  gem.authors = ["Changli Gao"]
10
10
  gem.email = ["xiaosuo@gmail.com"]
11
- gem.description = %q{A Ruby interface for QQWry IP database}
12
- gem.summary = %q{A Ruby interface for QQWry IP database}
11
+ gem.description = %q{A Ruby interface to QQWry IP database}
12
+ gem.summary = %q{A Ruby interface to QQWry IP database}
13
13
  gem.homepage = 'https://github.com/xiaosuo/qqwry'
14
14
  gem.files = `git ls-files`.split($/)
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/test/tc_record.rb CHANGED
@@ -57,3 +57,12 @@ class TC_Record < Test::Unit::TestCase
57
57
  @nil_area = true
58
58
  end
59
59
  end
60
+
61
+ class TC_Record_Abnormal < Test::Unit::TestCase
62
+ def test_invalid_encoding
63
+ io = StringIO.new("\x04\x03\x02\x01\xd6\xea\x96\x00\x96\x00")
64
+ r = QQWry::Record.new(0, io, 0)
65
+ assert_equal("\xe6\xa0\xaa", r.country.to_s)
66
+ assert_equal('', r.area.to_s)
67
+ end
68
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qqwry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease:
4
+ hash: 27
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Changli Gao
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-17 00:00:00 Z
18
+ date: 2012-12-18 00:00:00 +08:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: bindata
@@ -73,7 +74,7 @@ dependencies:
73
74
  version: "0"
74
75
  type: :development
75
76
  version_requirements: *id004
76
- description: A Ruby interface for QQWry IP database
77
+ description: A Ruby interface to QQWry IP database
77
78
  email:
78
79
  - xiaosuo@gmail.com
79
80
  executables:
@@ -96,6 +97,7 @@ files:
96
97
  - qqwry.gemspec
97
98
  - test/tc_database.rb
98
99
  - test/tc_record.rb
100
+ has_rdoc: true
99
101
  homepage: https://github.com/xiaosuo/qqwry
100
102
  licenses:
101
103
  - MIT
@@ -125,10 +127,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
127
  requirements: []
126
128
 
127
129
  rubyforge_project:
128
- rubygems_version: 1.8.24
130
+ rubygems_version: 1.3.7
129
131
  signing_key:
130
132
  specification_version: 3
131
- summary: A Ruby interface for QQWry IP database
133
+ summary: A Ruby interface to QQWry IP database
132
134
  test_files:
133
135
  - test/tc_database.rb
134
136
  - test/tc_record.rb