smstools 0.2.0 → 0.2.1

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
- SHA1:
3
- metadata.gz: 09a075d7c0f5acd2105e5a361cda66d81926f2bf
4
- data.tar.gz: 24febc16536d2174a802876034baee4533cb1512
2
+ SHA256:
3
+ metadata.gz: 7df349a1fd0872910cc9f6d2c23992d33807419968cbc9d68547549ef16a18bd
4
+ data.tar.gz: a30dd9cbb8550e475a322317b0cecdcb67c13a09f95449bf392c67d8200eb11c
5
5
  SHA512:
6
- metadata.gz: 934a838ced26fa606f876deb6720e15082de09c5c845a5672a28bae2fc390e4c471b9ce18b5cf1cc43db833f5941169db182b329f3cf94e1a4b7bafff163b44d
7
- data.tar.gz: f2f826aff33b5806db30a4d1882c694bb71deba907b4e75d27a6fb146937ea8603f3f38e48ab980cc44c26fbe3756ed6ebdd391e4e6ba581cb34199dde72b072
6
+ metadata.gz: edd17e186943ec7b89941e2eaba41279fadc39a27ee987cdb0efc3d4f8f4cbac85bb31a50afbe6d9df94fe7fd9f4498fe561861d9f60b97dd0bd39c49ed19ec8
7
+ data.tar.gz: b197d9070437eef8bf732134be1a9b3fcedcf71f71f95e0057d1ae214bde4c1b8d2f00769e58104df02acf776df71cf123bb34ead1d4a828c867a2ff1aae639c
@@ -1,3 +1,7 @@
1
+ ## 0.2.1 (18 Aug 2020)
2
+
3
+ * #7 Introduce `SmsTools.use_ascii_encoding` option (defaults to `true` for backwards-compatibility) that allows disabling the `:ascii` workaround encoding. See #6 and #7 for details. Thanks @kingsley-wang.
4
+
1
5
  ## 0.2.0 (2 March 2017)
2
6
 
3
7
  * 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)
data/README.md CHANGED
@@ -4,7 +4,7 @@ A small collection of Ruby and JavaScript classes implementing often needed func
4
4
  dealing with SMS messages.
5
5
 
6
6
  The gem can also be used in a Rails application as an engine. It integrates with the asset pipeline
7
- and gives you access to some clinet-side SMS manipulation functionality.
7
+ and gives you access to some client-side SMS manipulation functionality.
8
8
 
9
9
  ## Features
10
10
 
@@ -66,6 +66,16 @@ JavaScript part of the library, like so:
66
66
  //= require sms_tools
67
67
  SmsTools.use_gsm_encoding = false;
68
68
 
69
+ There is another alternative as well. As explained in this commit – f1ffd948d4b8c – SmsTools will by
70
+ default detect the encoding as `:ascii` if the SMS message contains ASCII-only symbols. The safest
71
+ way to send messages would be to use an ASCII subset of the GSM encodnig.
72
+
73
+ The `:ascii` encoding is informative only, however. Your SMS sending implementation will have to
74
+ decide how to handle it. You may also find it confusing that the dummy `:ascii` encoding does not
75
+ consider double-byte chars at all when counting the length of the message.
76
+
77
+ To disable this dummy `:ascii` encoding, set `SmsTools.use_ascii_encoding` to `false`.
78
+
69
79
  ## Installation
70
80
 
71
81
  Add this line to your application's Gemfile:
@@ -183,3 +193,4 @@ assumed. It might be possible to use it in other setups as well, but you're on y
183
193
  5. Commit your changes (`git commit -am 'Add some feature'`)
184
194
  6. Push to the branch (`git push origin my-new-feature`)
185
195
  7. Send a pull request.
196
+
@@ -43,8 +43,14 @@ class SmsTools.Message
43
43
  else
44
44
  SmsTools['use_gsm_encoding']
45
45
 
46
+ use_ascii_encoding: ->
47
+ if SmsTools['use_ascii_encoding'] == undefined
48
+ true
49
+ else
50
+ SmsTools['use_ascii_encoding']
51
+
46
52
  _encoding: ->
47
- if @asciiPattern.test(@text)
53
+ if @asciiPattern.test(@text) and @use_ascii_encoding()
48
54
  'ascii'
49
55
  else if @use_gsm_encoding() and @gsmEncodingPattern.test(@text)
50
56
  'gsm'
@@ -15,5 +15,13 @@ module SmsTools
15
15
  def use_gsm_encoding=(value)
16
16
  @use_gsm_encoding = value
17
17
  end
18
+
19
+ def use_ascii_encoding?
20
+ @use_ascii_encoding.nil? ? true : @use_ascii_encoding
21
+ end
22
+
23
+ def use_ascii_encoding=(value)
24
+ @use_ascii_encoding = value
25
+ end
18
26
  end
19
27
  end
@@ -25,7 +25,7 @@ module SmsTools
25
25
 
26
26
  def encoding
27
27
  @encoding ||=
28
- if text.ascii_only?
28
+ if text.ascii_only? and SmsTools.use_ascii_encoding?
29
29
  :ascii
30
30
  elsif SmsTools.use_gsm_encoding? and GsmEncoding.valid?(text)
31
31
  :gsm
@@ -1,3 +1,3 @@
1
1
  module SmsTools
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -56,6 +56,28 @@ describe SmsTools::EncodingDetection do
56
56
  detection_for('').encoding.must_equal :ascii
57
57
  end
58
58
  end
59
+
60
+ describe 'with SmsTools.use_ascii_encoding = false' do
61
+ before do
62
+ SmsTools.use_ascii_encoding = false
63
+ end
64
+
65
+ after do
66
+ SmsTools.use_ascii_encoding = true
67
+ end
68
+
69
+ it "returns GSM 03.38 as encoding for special symbols defined in GSM 03.38" do
70
+ detection_for('09azAZ@Δ¡¿£_!Φ"¥Γ#èΛ¤éΩ%ùΠ&ìΨòΣCΘΞ:Ø;ÄäøÆ,<Ööæ=ÑñÅß>Üüåɧà€~').encoding.must_equal :gsm
71
+ end
72
+
73
+ it 'returns GSM 03.38 for simple ASCII text' do
74
+ detection_for('Hello world.').encoding.must_equal :gsm
75
+ end
76
+
77
+ it "defaults to GSM 03.38 encoding for empty messages" do
78
+ detection_for('').encoding.must_equal :gsm
79
+ end
80
+ end
59
81
  end
60
82
 
61
83
  describe "message length" do
@@ -95,6 +117,26 @@ describe SmsTools::EncodingDetection do
95
117
  detection_for('Уникод: ^{}[~]|€\\').length.must_equal 17
96
118
  detection_for('Уникод: Σ: €').length.must_equal 12
97
119
  end
120
+
121
+ describe 'with SmsTools.use_gsm_encoding = false' do
122
+ before do
123
+ SmsTools.use_gsm_encoding = false
124
+ end
125
+
126
+ it "returns ASCII encoded length for some specific symbols which are also in GSM 03.38" do
127
+ detection_for('[]').length.must_equal 2
128
+ end
129
+ end
130
+
131
+ describe 'with SmsTools.use_ascii_encoding = false' do
132
+ before do
133
+ SmsTools.use_ascii_encoding = false
134
+ end
135
+
136
+ it "returns GSM 03.38 encoded length for some specific symbols which are also in ASCII" do
137
+ detection_for('[]').length.must_equal 4
138
+ end
139
+ end
98
140
  end
99
141
 
100
142
  describe "concatenated message parts counting" do
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitar Dimitrov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,7 +96,7 @@ homepage: https://github.com/mitio/smstools
96
96
  licenses:
97
97
  - MIT
98
98
  metadata: {}
99
- post_install_message:
99
+ post_install_message:
100
100
  rdoc_options: []
101
101
  require_paths:
102
102
  - lib
@@ -111,9 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.6.4
116
- signing_key:
114
+ rubygems_version: 3.0.3
115
+ signing_key:
117
116
  specification_version: 4
118
117
  summary: Small library of classes for common SMS-related functionality.
119
118
  test_files: