Permalink
Browse files

Handle messages with data_coding of 1

Some messages were found with data_coding of 1.  Although some specs state that this means they are encoded as ASCII, when dealing with O2 SMSCs, bits 2 and 3 of the data_coding are used to indicate encoding.  If they are both set to 0 then this indicates default character set, in our case HP-ROMAN8
  • Loading branch information...
1 parent c23291b commit d2428fcbe490d1c1efd1f1b8c8507841f24b30bc @tomafro tomafro committed Feb 25, 2011
Showing with 15 additions and 1 deletion.
  1. +2 −1 lib/smpp/pdu/deliver_sm.rb
  2. +13 −0 test/encoding_test.rb
@@ -61,6 +61,7 @@ def message_id
end
EURO_TOKEN = "_X_EURO_X_"
+
GSM_ESCAPED_CHARACTERS = {
?( => "\173", # {
?) => "\175", # }
@@ -140,7 +141,7 @@ def self.from_wire_data(seq, status, body)
Smpp::Base.logger.debug "DeliverSM with source_addr=#{source_addr}, destination_addr=#{destination_addr}"
end
- if options[:data_coding] == 0
+ if options[:data_coding] < 2
short_message.gsub!(/\215./) { |match| GSM_ESCAPED_CHARACTERS[match[1]] }
short_message = Iconv.conv("UTF-8", "HP-ROMAN8", short_message)
short_message.gsub!(EURO_TOKEN, "\342\202\254")
View
@@ -198,6 +198,19 @@ def test_should_convert_ucs_2_into_utf_8_where_data_coding_indicates_its_presenc
assert_equal expected, pdu.short_message
end
+ def test_should_decode_pound_sign_from_hp_roman_8_to_utf_8_when_data_coding_set_to_1
+ raw_data = <<-EOF
+ 0000 0096 0000 0005 0000 0000 0000 1b10
+ 0005 004d 6f6e 6579 416c 6572 7400 0101
+ 3434 3737 3738 3030 3036 3133 0000 0000
+ 0000 0000 0100 5fbb 506f 756e 6473 bb20
+ EOF
+
+ pdu = create_pdu(raw_data)
+ assert_equal Smpp::Pdu::DeliverSm, pdu.class
+ assert_equal "£Pounds£ ", pdu.short_message
+ end
+
protected
def create_pdu(raw_data)
hex_data = [raw_data.chomp.gsub(" ","").gsub(/\n/,"")].pack("H*")

0 comments on commit d2428fc

Please sign in to comment.