File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -104,8 +104,8 @@ def parse_control(src, current_pos = 0)
104104
105105 contents = src [ start , current_pos - start ]
106106 m = contents . match ( /([\* a-z]+)(\- ?\d +)?\* ?/ )
107- ctrl = m [ 1 ] . to_sym
108- val = m [ 2 ] . to_i unless m [ 2 ] . nil?
107+ ctrl = m [ 1 ] . to_sym unless m . nil? || m [ 1 ] . nil?
108+ val = m [ 2 ] . to_i unless m . nil? || m [ 2 ] . nil?
109109
110110 # we advance past the optional space if present
111111 current_pos += 1 if src [ current_pos ] == ' '
Original file line number Diff line number Diff line change 172172 section [ 1 ] [ :modifiers ] . has_key? ( :underline ) . should == false
173173 section [ 1 ] [ :text ] . should == 'World'
174174 end
175+
176+ it 'parses text when control matching fails' do
177+ src = '{\rtf1 Hello\~{World}}'
178+ section = parser . parse ( src ) . sections
179+ section [ 0 ] [ :text ] . should == 'Hello'
180+ section [ 1 ] [ :text ] . should == 'World'
181+ end
175182 end
176183
177184 context '#parse_control' do
232239 it 'advances the current positon past the optional space' do
233240 parser . parse_control ( 'Test ansi test' , 5 ) . last . should == 10
234241 end
242+
243+ it 'does not fail when control matching fails' do
244+ parser . parse_control ( '~}' ) [ 0 , 2 ] . should == [ '' , nil ]
245+ end
235246 end
236247
237248 context 'character set' do
You can’t perform that action at this time.
0 commit comments