ircparser 0.6.1 → 0.6.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.
- checksums.yaml +4 -4
- data/lib/ircparser.rb +2 -3
- data/lib/ircparser/error.rb +1 -1
- data/lib/ircparser/message.rb +1 -1
- data/lib/ircparser/prefix.rb +1 -1
- data/lib/ircparser/stream.rb +1 -1
- data/lib/ircparser/wire/rfc.rb +1 -1
- data/test/test_message.rb +56 -56
- data/test/test_prefix.rb +6 -6
- metadata +10 -17
- data/lib/ircparser/wire/json.rb +0 -265
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1262a7e23aab10553888d9d4221bd92135b2946c9eb62926151e922cf6bcc28
|
4
|
+
data.tar.gz: 1211d6f79d995dc880eae1f289bcd73cc9c6f2ecf4cd2bb7198e25aa10343114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3863279345f02af5357738b2c54488289259ad7f304da349663892af23f3cbe819a506175d139caf35edfb42d1db511289b89dba0e3fe82dea51baec989611a
|
7
|
+
data.tar.gz: 9dcca8e8329dd38534fec6dc95e88bae6e1cc3ad601f9983bc52c47484f4526c99bca64b450a88230f8ac330656b377edf24a8b9cd8238b09256697acbd7adb6
|
data/lib/ircparser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IRCParser - Internet Relay Chat Message Parser
|
2
2
|
#
|
3
|
-
# Copyright (C) 2015-
|
3
|
+
# Copyright (C) 2015-2020 Sadie Powell <sadie@witchery.services>
|
4
4
|
#
|
5
5
|
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
6
|
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
@@ -16,12 +16,11 @@
|
|
16
16
|
module IRCParser
|
17
17
|
|
18
18
|
# Public: The version of IRCParser in use.
|
19
|
-
VERSION = '0.6.
|
19
|
+
VERSION = '0.6.2'
|
20
20
|
end
|
21
21
|
|
22
22
|
require_relative 'ircparser/error'
|
23
23
|
require_relative 'ircparser/message'
|
24
24
|
require_relative 'ircparser/prefix'
|
25
25
|
require_relative 'ircparser/stream'
|
26
|
-
require_relative 'ircparser/wire/json'
|
27
26
|
require_relative 'ircparser/wire/rfc'
|
data/lib/ircparser/error.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IRCParser - Internet Relay Chat Message Parser
|
2
2
|
#
|
3
|
-
# Copyright (C) 2015-
|
3
|
+
# Copyright (C) 2015-2020 Sadie Powell <sadie@witchery.services>
|
4
4
|
#
|
5
5
|
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
6
|
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
data/lib/ircparser/message.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IRCParser - Internet Relay Chat Message Parser
|
2
2
|
#
|
3
|
-
# Copyright (C) 2015-
|
3
|
+
# Copyright (C) 2015-2020 Sadie Powell <sadie@witchery.services>
|
4
4
|
#
|
5
5
|
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
6
|
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
data/lib/ircparser/prefix.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IRCParser - Internet Relay Chat Message Parser
|
2
2
|
#
|
3
|
-
# Copyright (C) 2015-
|
3
|
+
# Copyright (C) 2015-2020 Sadie Powell <sadie@witchery.services>
|
4
4
|
#
|
5
5
|
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
6
|
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
data/lib/ircparser/stream.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IRCParser - Internet Relay Chat Message Parser
|
2
2
|
#
|
3
|
-
# Copyright (C) 2015-
|
3
|
+
# Copyright (C) 2015-2020 Sadie Powell <sadie@witchery.services>
|
4
4
|
#
|
5
5
|
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
6
|
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
data/lib/ircparser/wire/rfc.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IRCParser - Internet Relay Chat Message Parser
|
2
2
|
#
|
3
|
-
# Copyright (C) 2015-
|
3
|
+
# Copyright (C) 2015-2020 Sadie Powell <sadie@witchery.services>
|
4
4
|
#
|
5
5
|
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
6
|
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
data/test/test_message.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IRCParser - Internet Relay Chat Message Parser
|
2
2
|
#
|
3
|
-
# Copyright (C) 2015-
|
3
|
+
# Copyright (C) 2015-2020 Sadie Powell <sadie@witchery.services>
|
4
4
|
#
|
5
5
|
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
6
|
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
@@ -28,14 +28,14 @@ describe IRCParser::Message do
|
|
28
28
|
tags = { 'tag1' => 'value1', 'tag2' => nil, 'vendor1/tag3' => 'value2', 'vendor2/tag4' => nil }
|
29
29
|
parameters = [ 'param1', 'param2', 'param3 param3' ]
|
30
30
|
|
31
|
-
@message.tags.must_equal tags
|
32
|
-
@message.prefix.wont_be_nil
|
33
|
-
@message.prefix.nick.must_equal 'irc.example.com'
|
34
|
-
@message.command.must_equal 'COMMAND'
|
35
|
-
@message.parameters.must_equal parameters
|
31
|
+
_(@message.tags).must_equal tags
|
32
|
+
_(@message.prefix).wont_be_nil
|
33
|
+
_(@message.prefix.nick).must_equal 'irc.example.com'
|
34
|
+
_(@message.command).must_equal 'COMMAND'
|
35
|
+
_(@message.parameters).must_equal parameters
|
36
36
|
end
|
37
37
|
it 'should serialise back to the same text' do
|
38
|
-
@message.to_s.must_equal @text
|
38
|
+
_(@message.to_s).must_equal @text
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -47,14 +47,14 @@ describe IRCParser::Message do
|
|
47
47
|
it 'should consist of the correct components' do
|
48
48
|
parameters = [ 'param1', 'param2', 'param3 param3' ]
|
49
49
|
|
50
|
-
@message.tags.must_be_empty
|
51
|
-
@message.prefix.wont_be_nil
|
52
|
-
@message.prefix.nick.must_equal 'irc.example.com'
|
53
|
-
@message.command.must_equal 'COMMAND'
|
54
|
-
@message.parameters.must_equal parameters
|
50
|
+
_(@message.tags).must_be_empty
|
51
|
+
_(@message.prefix).wont_be_nil
|
52
|
+
_(@message.prefix.nick).must_equal 'irc.example.com'
|
53
|
+
_(@message.command).must_equal 'COMMAND'
|
54
|
+
_(@message.parameters).must_equal parameters
|
55
55
|
end
|
56
56
|
it 'should serialise back to the same text' do
|
57
|
-
@message.to_s.must_equal @text
|
57
|
+
_(@message.to_s).must_equal @text
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -67,13 +67,13 @@ describe IRCParser::Message do
|
|
67
67
|
tags = { 'tag1' => 'value1', 'tag2' => nil, 'vendor1/tag3' => 'value2', 'vendor2/tag4' => nil }
|
68
68
|
parameters = [ 'param1', 'param2', 'param3 param3' ]
|
69
69
|
|
70
|
-
@message.tags.must_equal tags
|
71
|
-
@message.prefix.must_be_nil
|
72
|
-
@message.command.must_equal 'COMMAND'
|
73
|
-
@message.parameters.must_equal parameters
|
70
|
+
_(@message.tags).must_equal tags
|
71
|
+
_(@message.prefix).must_be_nil
|
72
|
+
_(@message.command).must_equal 'COMMAND'
|
73
|
+
_(@message.parameters).must_equal parameters
|
74
74
|
end
|
75
75
|
it 'should serialise back to the same text' do
|
76
|
-
@message.to_s.must_equal @text
|
76
|
+
_(@message.to_s).must_equal @text
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -86,13 +86,13 @@ describe IRCParser::Message do
|
|
86
86
|
tags = { 'tag1' => 'value1', 'tag2' => nil, 'vendor1/tag3' => 'value2', 'vendor2/tag4' => nil }
|
87
87
|
parameters = [ 'param1', 'param2', 'param3 param3' ]
|
88
88
|
|
89
|
-
@message.tags.must_equal tags
|
90
|
-
@message.prefix.must_be_nil
|
91
|
-
@message.command.must_equal 'COMMAND'
|
92
|
-
@message.parameters.must_equal parameters
|
89
|
+
_(@message.tags).must_equal tags
|
90
|
+
_(@message.prefix).must_be_nil
|
91
|
+
_(@message.command).must_equal 'COMMAND'
|
92
|
+
_(@message.parameters).must_equal parameters
|
93
93
|
end
|
94
94
|
it 'should serialise back to the same text' do
|
95
|
-
@message.to_s.must_equal @text
|
95
|
+
_(@message.to_s).must_equal @text
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -103,13 +103,13 @@ describe IRCParser::Message do
|
|
103
103
|
@message = IRCParser::Message.parse @text
|
104
104
|
end
|
105
105
|
it 'should consist of the correct components' do
|
106
|
-
@message.tags.must_be_empty
|
107
|
-
@message.prefix.must_be_nil
|
108
|
-
@message.command.must_equal 'COMMAND'
|
109
|
-
@message.parameters.must_be_empty
|
106
|
+
_(@message.tags).must_be_empty
|
107
|
+
_(@message.prefix).must_be_nil
|
108
|
+
_(@message.command).must_equal 'COMMAND'
|
109
|
+
_(@message.parameters).must_be_empty
|
110
110
|
end
|
111
111
|
it 'should serialise back to the same text' do
|
112
|
-
@message.to_s.must_equal @text
|
112
|
+
_(@message.to_s).must_equal @text
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -122,11 +122,11 @@ describe IRCParser::Message do
|
|
122
122
|
it 'should escape correctly' do
|
123
123
|
tags = { 'foo' => @unescaped }
|
124
124
|
message = IRCParser::Message.new command: 'COMMAND', tags: tags
|
125
|
-
message.to_s.must_equal @text
|
125
|
+
_(message.to_s).must_equal @text
|
126
126
|
end
|
127
127
|
it 'should unescape correctly' do
|
128
128
|
message = IRCParser::Message.parse @text
|
129
|
-
message.tags['foo'].must_equal @unescaped
|
129
|
+
_(message.tags['foo']).must_equal @unescaped
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -136,11 +136,11 @@ describe IRCParser::Message do
|
|
136
136
|
@message = IRCParser::Message.parse @text
|
137
137
|
end
|
138
138
|
it 'should parse the trailing parameter properly' do
|
139
|
-
@message.parameters.size.must_equal 1
|
140
|
-
@message.parameters[0].must_equal 'param1 param1 '
|
139
|
+
_(@message.parameters.size).must_equal 1
|
140
|
+
_(@message.parameters[0]).must_equal 'param1 param1 '
|
141
141
|
end
|
142
142
|
it 'should serialize the trailing parameter properly' do
|
143
|
-
@message.to_s.must_equal @text
|
143
|
+
_(@message.to_s).must_equal @text
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -150,8 +150,8 @@ describe IRCParser::Message do
|
|
150
150
|
@message = IRCParser::Message.parse @text
|
151
151
|
end
|
152
152
|
it 'should parse the message properly' do
|
153
|
-
@message.command.must_equal 'COMMAND'
|
154
|
-
@message.parameters.size.must_equal 0
|
153
|
+
_(@message.command).must_equal 'COMMAND'
|
154
|
+
_(@message.parameters.size).must_equal 0
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
@@ -161,8 +161,8 @@ describe IRCParser::Message do
|
|
161
161
|
@message = IRCParser::Message.parse @text
|
162
162
|
end
|
163
163
|
it 'should parse the message properly' do
|
164
|
-
@message.command.must_equal 'COMMAND'
|
165
|
-
@message.parameters.size.must_equal 0
|
164
|
+
_(@message.command).must_equal 'COMMAND'
|
165
|
+
_(@message.parameters.size).must_equal 0
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -172,12 +172,12 @@ describe IRCParser::Message do
|
|
172
172
|
@message = IRCParser::Message.parse @text
|
173
173
|
end
|
174
174
|
it 'should parse the trailing parameter properly' do
|
175
|
-
@message.command.must_equal 'COMMAND'
|
176
|
-
@message.parameters.size.must_equal 1
|
177
|
-
@message.parameters[0].must_equal ''
|
175
|
+
_(@message.command).must_equal 'COMMAND'
|
176
|
+
_(@message.parameters.size).must_equal 1
|
177
|
+
_(@message.parameters[0]).must_equal ''
|
178
178
|
end
|
179
179
|
it 'should serialize the trailing parameter properly' do
|
180
|
-
@message.to_s.must_equal @text
|
180
|
+
_(@message.to_s).must_equal @text
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
@@ -187,10 +187,10 @@ describe IRCParser::Message do
|
|
187
187
|
@message = IRCParser::Message.parse @text
|
188
188
|
end
|
189
189
|
it 'should strip invalid and trailing escapes' do
|
190
|
-
@message.tags['foo'].must_equal 'wibbleZwobble'
|
190
|
+
_(@message.tags['foo']).must_equal 'wibbleZwobble'
|
191
191
|
end
|
192
192
|
it 'should serialise back to a well formed value' do
|
193
|
-
@message.to_s.must_equal '@foo=wibbleZwobble COMMAND'
|
193
|
+
_(@message.to_s).must_equal '@foo=wibbleZwobble COMMAND'
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
@@ -202,44 +202,44 @@ describe IRCParser::Message do
|
|
202
202
|
@message = IRCParser::Message.new tags: @tags, command: 'COMMAND'
|
203
203
|
end
|
204
204
|
it 'should serialise without creating malformed tags' do
|
205
|
-
@message.to_s.must_equal '@foo=wibble\\\\Zwobble\\\\ COMMAND'
|
205
|
+
_(@message.to_s).must_equal '@foo=wibble\\\\Zwobble\\\\ COMMAND'
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
209
|
describe 'when checking we can handle serialising malformed parameters' do
|
210
210
|
it 'should throw an IRCParser::Error when a non <trailing> parameter contains spaces' do
|
211
|
-
proc {
|
211
|
+
_(proc {
|
212
212
|
message = IRCParser::Message.new command: 'COMMAND', parameters: [ 'param1 param1', 'param2' ]
|
213
213
|
message.to_s
|
214
|
-
}.must_raise IRCParser::Error
|
214
|
+
}).must_raise IRCParser::Error
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
218
|
describe 'when checking we handle parsing malformed messages properly' do
|
219
219
|
it 'should throw an IRCParser::Error when trying to parse an empty message' do
|
220
|
-
proc {
|
220
|
+
_(proc {
|
221
221
|
IRCParser::Message.parse ''
|
222
|
-
}.must_raise IRCParser::Error
|
222
|
+
}).must_raise IRCParser::Error
|
223
223
|
end
|
224
224
|
it 'should throw an IRCParser::Error when trying to parse an whitespace message' do
|
225
|
-
proc {
|
225
|
+
_(proc {
|
226
226
|
IRCParser::Message.parse ' '
|
227
|
-
}.must_raise IRCParser::Error
|
227
|
+
}).must_raise IRCParser::Error
|
228
228
|
end
|
229
229
|
it 'should throw an IRCParser::Error when trying to parse a message with tags and a prefix but no command' do
|
230
|
-
proc {
|
230
|
+
_(proc {
|
231
231
|
IRCParser::Message.parse '@foo;bar=baz :irc.example.com'
|
232
|
-
}.must_raise IRCParser::Error
|
232
|
+
}).must_raise IRCParser::Error
|
233
233
|
end
|
234
234
|
it 'should throw an IRCParser::Error when trying to parse a message with tags but no command' do
|
235
|
-
proc {
|
235
|
+
_(proc {
|
236
236
|
IRCParser::Message.parse '@foo;bar=baz'
|
237
|
-
}.must_raise IRCParser::Error
|
237
|
+
}).must_raise IRCParser::Error
|
238
238
|
end
|
239
239
|
it 'should throw an IRCParser::Error when trying to parse a message with a prefix but no command' do
|
240
|
-
proc {
|
240
|
+
_(proc {
|
241
241
|
IRCParser::Message.parse ':irc.example.com'
|
242
|
-
}.must_raise IRCParser::Error
|
242
|
+
}).must_raise IRCParser::Error
|
243
243
|
end
|
244
244
|
end
|
245
245
|
end
|
data/test/test_prefix.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# IRCParser - Internet Relay Chat Message Parser
|
2
2
|
#
|
3
|
-
# Copyright (C) 2015-
|
3
|
+
# Copyright (C) 2015-2020 Sadie Powell <sadie@witchery.services>
|
4
4
|
#
|
5
5
|
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
6
|
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
@@ -56,14 +56,14 @@ describe IRCParser::Prefix do
|
|
56
56
|
it 'should consist of the correct components' do
|
57
57
|
%i(nick user host).each do |component|
|
58
58
|
if deserialized[component].nil?
|
59
|
-
@message.prefix.send(component).must_be_nil
|
59
|
+
_(@message.prefix.send(component)).must_be_nil
|
60
60
|
else
|
61
|
-
@message.prefix.send(component).must_equal deserialized[component]
|
61
|
+
_(@message.prefix.send(component)).must_equal deserialized[component]
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
65
|
it 'should serialise back to the same text' do
|
66
|
-
@message.to_s.must_equal @text
|
66
|
+
_(@message.to_s).must_equal @text
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
@@ -80,9 +80,9 @@ describe IRCParser::Prefix do
|
|
80
80
|
MALFORMED.each do |prefix|
|
81
81
|
describe 'when checking an invalid user prefix' do
|
82
82
|
it 'should throw an IRCParser::Error when components are missing' do
|
83
|
-
proc {
|
83
|
+
_(proc {
|
84
84
|
IRCParser::Message.parse ":#{prefix} COMMAND"
|
85
|
-
}.must_raise IRCParser::Error
|
85
|
+
}).must_raise IRCParser::Error
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ircparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Sadie Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -16,34 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 5.10.1
|
19
|
+
version: '5.13'
|
23
20
|
type: :development
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '5.
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 5.10.1
|
26
|
+
version: '5.13'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: rake
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
33
|
+
version: 13.0.1
|
40
34
|
type: :development
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
40
|
+
version: 13.0.1
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: tomdoc
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,7 +53,7 @@ dependencies:
|
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: 0.2.5
|
61
55
|
description: A standards compliant parser for the IRCv3 message format.
|
62
|
-
email:
|
56
|
+
email: sadie@witchery.services
|
63
57
|
executables: []
|
64
58
|
extensions: []
|
65
59
|
extra_rdoc_files: []
|
@@ -69,11 +63,10 @@ files:
|
|
69
63
|
- lib/ircparser/message.rb
|
70
64
|
- lib/ircparser/prefix.rb
|
71
65
|
- lib/ircparser/stream.rb
|
72
|
-
- lib/ircparser/wire/json.rb
|
73
66
|
- lib/ircparser/wire/rfc.rb
|
74
67
|
- test/test_message.rb
|
75
68
|
- test/test_prefix.rb
|
76
|
-
homepage: https://github.com/
|
69
|
+
homepage: https://github.com/SadieCat/ircparser-ruby
|
77
70
|
licenses:
|
78
71
|
- ISC
|
79
72
|
metadata: {}
|
@@ -92,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
85
|
- !ruby/object:Gem::Version
|
93
86
|
version: '0'
|
94
87
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
88
|
+
rubygems_version: 3.1.2
|
96
89
|
signing_key:
|
97
90
|
specification_version: 4
|
98
91
|
summary: An IRCv3 message parser.
|
data/lib/ircparser/wire/json.rb
DELETED
@@ -1,265 +0,0 @@
|
|
1
|
-
# IRCParser - Internet Relay Chat Message Parser
|
2
|
-
#
|
3
|
-
# Copyright (C) 2015-2019 Peter "SaberUK" Powell <petpow@saberuk.com>
|
4
|
-
#
|
5
|
-
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
|
-
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
7
|
-
# in all copies.
|
8
|
-
#
|
9
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
10
|
-
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
11
|
-
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
13
|
-
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
14
|
-
# OF THIS SOFTWARE.
|
15
|
-
|
16
|
-
require 'json'
|
17
|
-
|
18
|
-
module IRCParser
|
19
|
-
|
20
|
-
# Internal: Implements objectification and stringification for the JSON wire format.
|
21
|
-
module JSONWireFormat
|
22
|
-
|
23
|
-
# Internal: Objectifies a message from the JSON wire format to an IRCParser::Message.
|
24
|
-
#
|
25
|
-
# str - A String containing a message in the JSON wire format.
|
26
|
-
def self.objectify str
|
27
|
-
|
28
|
-
# Ruby really needs some kind of basic type checking.
|
29
|
-
unless str.is_a? String
|
30
|
-
raise IRCParser::Error.new(str), "message is not a String"
|
31
|
-
end
|
32
|
-
|
33
|
-
# Parse and validate the JSON object.
|
34
|
-
message = JSON.parse str.lstrip, max_nesting: 6 rescue nil
|
35
|
-
unless message.is_a? Hash
|
36
|
-
raise IRCParser::Error.new(str), 'message is not a JSON object'
|
37
|
-
end
|
38
|
-
|
39
|
-
{ tags: Hash.new, parameters: Array.new }
|
40
|
-
|
41
|
-
# Have we encountered IRCv3 message tags?
|
42
|
-
components = Hash.new
|
43
|
-
components[:tags] = if message.include? 'tags'
|
44
|
-
raise IRCParser::Error.new(str), 'message tags are not a JSON object' unless message[:tags].is_a? Hash
|
45
|
-
message[:tags]
|
46
|
-
else
|
47
|
-
Hash.new
|
48
|
-
end
|
49
|
-
|
50
|
-
components[:prefix] = if message.include? 'source'
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
if current_token != nil && current_token[0] == '@'
|
55
|
-
components[:tags] = self.__objectify_tags current_token
|
56
|
-
current_token = self.__get_token message
|
57
|
-
end
|
58
|
-
|
59
|
-
# Have we encountered the prefix of this message?
|
60
|
-
if current_token != nil && current_token[0] == ':'
|
61
|
-
components[:prefix] = self.__objectify_prefix current_token
|
62
|
-
current_token = self.__get_token message
|
63
|
-
end
|
64
|
-
|
65
|
-
# The command parameter is mandatory.
|
66
|
-
if current_token != nil
|
67
|
-
components[:command] = current_token.upcase
|
68
|
-
current_token = self.__get_final_token message
|
69
|
-
else
|
70
|
-
raise IRCParser::Error.new(str), 'message is missing the command name'
|
71
|
-
end
|
72
|
-
|
73
|
-
# Try to parse all of the remaining parameters.
|
74
|
-
components[:parameters] = Array.new
|
75
|
-
while current_token != nil
|
76
|
-
components[:parameters] << current_token
|
77
|
-
current_token = self.__get_final_token message
|
78
|
-
end
|
79
|
-
|
80
|
-
return IRCParser::Message.new components
|
81
|
-
end
|
82
|
-
|
83
|
-
# Internal: Stringifies a message from an IRCParser::Message to the JSON wire format.
|
84
|
-
#
|
85
|
-
# obj - An IRCParser::Message to stringify to the JSON wire format.
|
86
|
-
def self.stringify obj
|
87
|
-
|
88
|
-
# Ruby really needs some kind of basic type checking.
|
89
|
-
unless obj.is_a? IRCParser::Message
|
90
|
-
raise IRCParser::Error.new(obj), "message is not an IRCParser::Message"
|
91
|
-
end
|
92
|
-
|
93
|
-
# Stringify the tags.
|
94
|
-
buffer = String.new
|
95
|
-
unless obj.tags.empty?
|
96
|
-
buffer += '@'
|
97
|
-
buffer += self.__stringify_tags obj.tags
|
98
|
-
buffer += ' '
|
99
|
-
end
|
100
|
-
|
101
|
-
# Stringify the prefix.
|
102
|
-
unless obj.prefix.nil?
|
103
|
-
buffer += ':'
|
104
|
-
buffer += self.__stringify_prefix obj.prefix
|
105
|
-
buffer += ' '
|
106
|
-
end
|
107
|
-
|
108
|
-
# Stringify the command.
|
109
|
-
buffer += obj.command
|
110
|
-
|
111
|
-
# Stringify the parameters
|
112
|
-
buffer += self.__stringify_parameters obj.parameters
|
113
|
-
|
114
|
-
# We're done!
|
115
|
-
return buffer
|
116
|
-
end
|
117
|
-
|
118
|
-
private
|
119
|
-
|
120
|
-
# Internal: A regular expression which matches a n!u@h mask.
|
121
|
-
MATCH_PREFIX = /^:(?<nick>[^@!]+) (?:!(?<user>[^@]+))? (?:@(?<host>.+))?$/x
|
122
|
-
|
123
|
-
# Internal: A regular expression which matches a tag.
|
124
|
-
MATCH_TAG = /^(?<name>[^\s=]+?)(?:=(?<value>[^\s;]+))?$/
|
125
|
-
|
126
|
-
# Internal: The characters which need to be escaped in tag values.
|
127
|
-
TAG_ESCAPES = {
|
128
|
-
'\\\\' => '\\',
|
129
|
-
'\:' => ';',
|
130
|
-
'\s' => "\s",
|
131
|
-
'\r' => "\r",
|
132
|
-
'\n' => "\n",
|
133
|
-
}
|
134
|
-
|
135
|
-
# Internal: Retrieves a space delimited token from the buffer.
|
136
|
-
#
|
137
|
-
# buffer - The buffer to retrieve the token from.
|
138
|
-
def self.__get_token buffer
|
139
|
-
return nil if buffer.empty?
|
140
|
-
position = buffer.index ' '
|
141
|
-
if position == nil
|
142
|
-
token = buffer.clone
|
143
|
-
buffer.clear
|
144
|
-
return token
|
145
|
-
end
|
146
|
-
token = buffer.slice! 0...position
|
147
|
-
position = buffer.index /\S+/
|
148
|
-
if position == nil
|
149
|
-
buffer.clear
|
150
|
-
else
|
151
|
-
buffer.slice! 0...position
|
152
|
-
end
|
153
|
-
return token
|
154
|
-
end
|
155
|
-
|
156
|
-
# Internal: Retrieves a space delimited token that may be a <trailing> parameter.
|
157
|
-
#
|
158
|
-
# buffer - The buffer to retrieve the token from.
|
159
|
-
def self.__get_final_token buffer
|
160
|
-
return nil if buffer.empty?
|
161
|
-
if buffer[0] == ':'
|
162
|
-
token = buffer[1..-1]
|
163
|
-
buffer.clear
|
164
|
-
return token
|
165
|
-
end
|
166
|
-
return self.__get_token buffer
|
167
|
-
end
|
168
|
-
|
169
|
-
# Internal: Objectifies the prefix from the JSON wire format to an IRCParser::Prefix.
|
170
|
-
#
|
171
|
-
# token - A String containing the prefix in the JSON wire format.
|
172
|
-
def self.__objectify_prefix prefix
|
173
|
-
unless MATCH_PREFIX =~ prefix
|
174
|
-
raise IRCParser::Error.new(prefix), 'prefix is not a user mask or server name'
|
175
|
-
end
|
176
|
-
return IRCParser::Prefix.new nick: $~[:nick], user: $~[:user], host: $~[:host]
|
177
|
-
end
|
178
|
-
|
179
|
-
# Internal: Objectifies tags from the JSON wire format to a Hash.
|
180
|
-
#
|
181
|
-
# token - A String containing tags in the JSON wire format.
|
182
|
-
def self.__objectify_tags token
|
183
|
-
tags = Hash.new
|
184
|
-
token[1..-1].split(';').each do |tag|
|
185
|
-
if tag =~ MATCH_TAG
|
186
|
-
value = nil
|
187
|
-
value_index = 0
|
188
|
-
while $~['value'] != nil && value_index < $~['value'].size
|
189
|
-
value ||= String.new
|
190
|
-
if $~['value'][value_index] == '\\'
|
191
|
-
escape = $~['value'].slice(value_index, 2)
|
192
|
-
if TAG_ESCAPES.include? escape
|
193
|
-
value += TAG_ESCAPES[escape]
|
194
|
-
value_index += 1
|
195
|
-
end
|
196
|
-
else
|
197
|
-
value += $~['value'][value_index]
|
198
|
-
end
|
199
|
-
value_index += 1
|
200
|
-
end
|
201
|
-
tags[$~['name']] = value
|
202
|
-
else
|
203
|
-
raise IRCParser::Error.new(tag), 'tag is malformed'
|
204
|
-
end
|
205
|
-
end
|
206
|
-
return tags
|
207
|
-
end
|
208
|
-
|
209
|
-
# Internal: Stringifies parameters from an Array to the JSON wire format.
|
210
|
-
#
|
211
|
-
# parameters - An Array to stringify to the JSON wire format.
|
212
|
-
def self.__stringify_parameters parameters
|
213
|
-
buffer = String.new
|
214
|
-
parameters.each_with_index do |parameter, index|
|
215
|
-
trailing = parameter.include? ' '
|
216
|
-
if trailing && index != parameters.size-1
|
217
|
-
raise IRCParser::Error.new(parameter), 'only the last parameter may contain spaces'
|
218
|
-
end
|
219
|
-
|
220
|
-
buffer += ' '
|
221
|
-
if trailing || parameter.empty?
|
222
|
-
buffer += ':'
|
223
|
-
buffer += parameter
|
224
|
-
break
|
225
|
-
end
|
226
|
-
buffer += parameter
|
227
|
-
end
|
228
|
-
return buffer
|
229
|
-
end
|
230
|
-
|
231
|
-
# Internal: Stringifies the prefix from an IRCParser::Prefix to the JSON wire format.
|
232
|
-
#
|
233
|
-
# tags - An IRCParser::Prefix to stringify to the JSON wire format.
|
234
|
-
def self.__stringify_prefix prefix
|
235
|
-
buffer = prefix.nick
|
236
|
-
buffer += "!#{prefix.user}" unless prefix.user.nil?
|
237
|
-
buffer += "@#{prefix.host}" unless prefix.host.nil?
|
238
|
-
return buffer
|
239
|
-
end
|
240
|
-
|
241
|
-
# Internal: Stringifies tags from a Hash to the JSON wire format.
|
242
|
-
#
|
243
|
-
# tags - A Hash of tags to stringify to the JSON wire format.
|
244
|
-
def self.__stringify_tags tags
|
245
|
-
buffer = String.new
|
246
|
-
tags.each.with_index do |tag, idx|
|
247
|
-
key, value = tag
|
248
|
-
buffer += key
|
249
|
-
unless value.nil?
|
250
|
-
buffer += '='
|
251
|
-
value.each_char do |chr|
|
252
|
-
if TAG_ESCAPES.has_value? chr
|
253
|
-
buffer += TAG_ESCAPES.key chr
|
254
|
-
else
|
255
|
-
buffer += chr
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
buffer += ';' if idx < tags.size - 1
|
260
|
-
end
|
261
|
-
return buffer
|
262
|
-
end
|
263
|
-
|
264
|
-
end
|
265
|
-
end
|