Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/message_format/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def parse_text ( parent_type )
(is_arg_style and is_whitespace(char))
)
text << char
found_closing_quote = false
while @index + 1 < @length
@index += 1
char = @pattern[@index]
Expand All @@ -102,11 +103,17 @@ def parse_text ( parent_type )
@index += 1
elsif char == '\'' # end of quoted
@index += 1
found_closing_quote = true
break
else
text << char
end
end
# If no closing quote was found, increment past the last character
# to avoid reprocessing it in the outer loop
if !found_closing_quote
@index += 1
end
else # lone ' is just a '
text << '\''
# already incremented
Expand Down
7 changes: 7 additions & 0 deletions spec/message_format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
expect(message).to eql('This isn\'t a {\'simple\'} \'string\'')
end

it 'handles escaped single apostrophe escapes' do
pattern = 'Hello \'{literal}!'
message = MessageFormat.new(pattern, 'en-US').format()

expect(message).to eql('Hello {literal}!')
end

it 'accepts arguments' do
pattern = 'x{ arg }z'
message = MessageFormat.new(pattern, 'en-US').format({ :arg => 'y' })
Expand Down