Skip to content

Commit

Permalink
Don't return binary Strings in Timezone#friendly_identifier.
Browse files Browse the repository at this point in the history
(cherry picked from commit d213131)
  • Loading branch information
philr committed Mar 17, 2017
1 parent 7f8d6ab commit ed27ed4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/tzinfo/timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,9 @@ def friendly_identifier(skip_first_part = false)
elsif parts.length == 1
parts[0]
else
if skip_first_part
result = String.new
else
result = parts[0] + ' - '
end

parts[1, parts.length - 1].reverse_each {|part|
prefix = skip_first_part ? nil : "#{parts[0]} - "

parts = parts.drop(1).map do |part|
part.gsub!(/_/, ' ')

if part.index(/[a-z]/)
Expand All @@ -254,13 +250,11 @@ def friendly_identifier(skip_first_part = false)
# Missing an apostrophe if two consecutive upper case characters.
part.gsub!(/([A-Z])([A-Z])/, '\1\'\2')
end

result << part
result << ', '
}

result.slice!(result.length - 2, 2)
result

part
end

"#{prefix}#{parts.reverse.join(', ')}"
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/tc_timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ def test_friendly_identifier
assert_equal('UTC', TestTimezone.new('UTC').friendly_identifier)
end

def test_friendly_identifier_non_binary_encoding
refute_equal(Encoding::ASCII_8BIT, TestTimezone.new('Europe/Paris').friendly_identifier(true).encoding)
refute_equal(Encoding::ASCII_8BIT, TestTimezone.new('Europe/Paris').friendly_identifier(false).encoding)
end

def test_to_s
assert_equal('Europe - Paris', TestTimezone.new('Europe/Paris').to_s)
assert_equal('America - Knox, Indiana', TestTimezone.new('America/Indiana/Knox').to_s)
Expand Down

0 comments on commit ed27ed4

Please sign in to comment.