smstools 0.1.1 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df6410b78260b2fc62e716c889ca5502bd91c477
4
- data.tar.gz: 57b8f13df3b6453e168eac420e51d4ef959ebf71
3
+ metadata.gz: 09a075d7c0f5acd2105e5a361cda66d81926f2bf
4
+ data.tar.gz: 24febc16536d2174a802876034baee4533cb1512
5
5
  SHA512:
6
- metadata.gz: d0ca45861515b43a9a4d9bec38479af3e6c92f080d1307d2e8399477647382ac37e2019041830ad236a0934298e0ca9b70292af5362ba572e22b34d4faed3951
7
- data.tar.gz: 0f0a5874e6b5fe3367fe32969b7376c274ec22183b9edbed4f7baf79877034dc3c8f9ac619e88951bc0d5c206bc6615d37bc2ca720af6300e4bca90bdeb1cd23
6
+ metadata.gz: 934a838ced26fa606f876deb6720e15082de09c5c845a5672a28bae2fc390e4c471b9ce18b5cf1cc43db833f5941169db182b329f3cf94e1a4b7bafff163b44d
7
+ data.tar.gz: f2f826aff33b5806db30a4d1882c694bb71deba907b4e75d27a6fb146937ea8603f3f38e48ab980cc44c26fbe3756ed6ebdd391e4e6ba581cb34199dde72b072
@@ -1,3 +1,8 @@
1
+ ## 0.2.0 (2 March 2017)
2
+
3
+ * The non-breaking space character (0x00A0 in Unicode and "\xC2\xA0" in UTF-8) is no longer regarded as a valid GSM 7-bit symbol. [#4](https://github.com/livebg/smstools/issues/4)
4
+ * GsmEncoding.to_utf8 will now raise errors in case the provided argument is not a valid GSM 7-bit text.
5
+
1
6
  ## 0.1.1 (18 April 2016)
2
7
 
3
8
  * Replaces small c with cedilla to capital one, as per the GSM 03.38 standard (by @skliask)
data/Rakefile CHANGED
@@ -1,11 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
2
3
 
3
- task :test do
4
- test_files = Dir[File.expand_path('../spec/**/*_spec.rb', __FILE__)]
5
- command = "ruby -Ispec #{test_files.join ' '}"
4
+ task default: :test
6
5
 
7
- puts "Running #{command}"
8
- system command
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'spec'
8
+ t.test_files = FileList['spec/**/*_spec.rb']
9
+ t.verbose = true
9
10
  end
10
-
11
- task default: :test
@@ -4,6 +4,8 @@ module SmsTools
4
4
  module GsmEncoding
5
5
  extend self
6
6
 
7
+ GSM_EXTENSION_TABLE_ESCAPE_CODE = "\x1B".freeze
8
+
7
9
  UTF8_TO_GSM_BASE_TABLE = {
8
10
  0x0040 => "\x00", # COMMERCIAL AT
9
11
  0x00A3 => "\x01", # POUND SIGN
@@ -32,7 +34,7 @@ module SmsTools
32
34
  0x03A3 => "\x18", # GREEK CAPITAL LETTER SIGMA
33
35
  0x0398 => "\x19", # GREEK CAPITAL LETTER THETA
34
36
  0x039E => "\x1A", # GREEK CAPITAL LETTER XI
35
- 0x00A0 => "\x1B", # ESCAPE TO EXTENSION TABLE
37
+ nil => "\x1B", # ESCAPE TO EXTENSION TABLE or NON-BREAKING SPACE
36
38
  0x00C6 => "\x1C", # LATIN CAPITAL LETTER AE
37
39
  0x00E6 => "\x1D", # LATIN SMALL LETTER AE
38
40
  0x00DF => "\x1E", # LATIN SMALL LETTER SHARP S (German)
@@ -176,20 +178,25 @@ module SmsTools
176
178
  def to_utf8(gsm_encoded_string)
177
179
  utf8_encoded_string = ''
178
180
  escape = false
179
- escape_code = "\e".freeze
180
181
 
181
182
  gsm_encoded_string.each_char do |char|
182
- if char == escape_code
183
+ if char == GSM_EXTENSION_TABLE_ESCAPE_CODE
183
184
  escape = true
184
185
  elsif escape
185
186
  escape = false
186
- utf8_encoded_string << [GSM_TO_UTF8[escape_code + char]].pack('U')
187
+ utf8_encoded_string << [fetch_utf8_char(GSM_EXTENSION_TABLE_ESCAPE_CODE + char)].pack('U')
187
188
  else
188
- utf8_encoded_string << [GSM_TO_UTF8[char]].pack('U')
189
+ utf8_encoded_string << [fetch_utf8_char(char)].pack('U')
189
190
  end
190
191
  end
191
192
 
192
193
  utf8_encoded_string
193
194
  end
195
+
196
+ private
197
+
198
+ def fetch_utf8_char(char)
199
+ GSM_TO_UTF8.fetch(char) { raise "Unsupported symbol in GSM-7 encoding: #{char}" }
200
+ end
194
201
  end
195
202
  end
@@ -1,3 +1,3 @@
1
1
  module SmsTools
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -29,6 +29,12 @@ describe SmsTools::EncodingDetection do
29
29
  detection_for('∞').encoding.must_equal :unicode
30
30
  end
31
31
 
32
+ it 'considers the non-breaking space character as a non-GSM Unicode symbol' do
33
+ non_breaking_space = "\xC2\xA0"
34
+
35
+ detection_for(non_breaking_space).encoding.must_equal :unicode
36
+ end
37
+
32
38
  describe 'with SmsTools.use_gsm_encoding = false' do
33
39
  before do
34
40
  SmsTools.use_gsm_encoding = false
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'sms_tools'
3
+
4
+ describe SmsTools::GsmEncoding do
5
+ describe 'from_utf8' do
6
+ it 'converts simple UTF-8 text to GSM 03.38' do
7
+ SmsTools::GsmEncoding.from_utf8('simple').must_equal 'simple'
8
+ end
9
+
10
+ it 'converts UTF-8 text with double-byte chars to GSM 03.38' do
11
+ SmsTools::GsmEncoding.from_utf8('foo []').must_equal "foo \e<\e>"
12
+ end
13
+
14
+ it 'raises an exception if the UTF-8 text contains chars outside of GSM 03.38' do
15
+ -> { SmsTools::GsmEncoding.from_utf8('баба') }.must_raise RuntimeError, /Unsupported symbol in GSM-7 encoding/
16
+ end
17
+ end
18
+
19
+ describe 'to_utf8' do
20
+ it 'converts simple GSM 03.38 to UTF-8' do
21
+ SmsTools::GsmEncoding.to_utf8('simple').must_equal 'simple'
22
+ end
23
+
24
+ it 'converts UTF-8 text with double-byte chars to GSM 03.38' do
25
+ SmsTools::GsmEncoding.to_utf8("GSM \e<\e>").must_equal 'GSM []'
26
+ end
27
+
28
+ it 'raises an exception if the UTF-8 text contains chars outside of GSM 03.38' do
29
+ -> { SmsTools::GsmEncoding.to_utf8('баба') }.must_raise RuntimeError, /Unsupported symbol in GSM-7 encoding/
30
+ end
31
+
32
+ it 'ignores single occurrences of the GSM-7 extension table escape code' do
33
+ SmsTools::GsmEncoding.to_utf8("\x1B").must_equal ''
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smstools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitar Dimitrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,6 +90,7 @@ files:
90
90
  - lib/smstools.rb
91
91
  - smstools.gemspec
92
92
  - spec/sms_tools/encoding_detection_spec.rb
93
+ - spec/sms_tools/gsm_encoding_spec.rb
93
94
  - spec/spec_helper.rb
94
95
  homepage: https://github.com/mitio/smstools
95
96
  licenses:
@@ -111,10 +112,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.2.2
115
+ rubygems_version: 2.6.4
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: Small library of classes for common SMS-related functionality.
118
119
  test_files:
119
120
  - spec/sms_tools/encoding_detection_spec.rb
121
+ - spec/sms_tools/gsm_encoding_spec.rb
120
122
  - spec/spec_helper.rb