@@ -40,6 +40,17 @@ def detailed_message
4040 end
4141end
4242
43+ class ExceptionWithDetailedMessageReturningEncodedString < Exception
44+ def initialize ( message , encoding )
45+ super ( message )
46+ @encoding = encoding
47+ end
48+
49+ def detailed_message
50+ "abc #{ self } xyz" . encode ( @encoding )
51+ end
52+ end
53+
4354shared_examples "Report or Event tests" do |class_to_test |
4455 context "metadata" do
4556 include_examples (
@@ -1465,24 +1476,75 @@ def detailed_message
14651476 }
14661477 end
14671478
1468- it "uses Exception#detailed_message if available" do
1469- Bugsnag . notify ( ExceptionWithDetailedMessage . new ( "some message" ) )
1479+ context "#detailed_message" do
1480+ it "uses Exception#detailed_message if available" do
1481+ Bugsnag . notify ( ExceptionWithDetailedMessage . new ( "some message" ) )
14701482
1471- expect ( Bugsnag ) . to have_sent_notification { |payload , headers |
1472- exception = get_exception_from_payload ( payload )
1473- expect ( exception [ "errorClass" ] ) . to eq ( "ExceptionWithDetailedMessage" )
1474- expect ( exception [ "message" ] ) . to eq ( "some message with some extra detail" )
1475- }
1476- end
1483+ expect ( Bugsnag ) . to have_sent_notification { |payload , headers |
1484+ exception = get_exception_from_payload ( payload )
1485+ expect ( exception [ "errorClass" ] ) . to eq ( "ExceptionWithDetailedMessage" )
1486+ expect ( exception [ "message" ] ) . to eq ( "some message with some extra detail" )
1487+ }
1488+ end
14771489
1478- it "handles implementations of Exception#detailed_message with no 'highlight' parameter" do
1479- Bugsnag . notify ( ExceptionWithDetailedMessageButNoHighlight . new ( "some message" ) )
1490+ it "handles implementations of Exception#detailed_message with no 'highlight' parameter" do
1491+ Bugsnag . notify ( ExceptionWithDetailedMessageButNoHighlight . new ( "some message" ) )
14801492
1481- expect ( Bugsnag ) . to have_sent_notification { |payload , headers |
1482- exception = get_exception_from_payload ( payload )
1483- expect ( exception [ "errorClass" ] ) . to eq ( "ExceptionWithDetailedMessageButNoHighlight" )
1484- expect ( exception [ "message" ] ) . to eq ( "detail about 'some message'" )
1485- }
1493+ expect ( Bugsnag ) . to have_sent_notification { |payload , headers |
1494+ exception = get_exception_from_payload ( payload )
1495+ expect ( exception [ "errorClass" ] ) . to eq ( "ExceptionWithDetailedMessageButNoHighlight" )
1496+ expect ( exception [ "message" ] ) . to eq ( "detail about 'some message'" )
1497+ }
1498+ end
1499+
1500+ it "converts ASCII_8BIT encoding to UTF-8" do
1501+ Bugsnag . notify ( Exception . new ( "大好き\n 大好き" ) )
1502+
1503+ expect ( Bugsnag ) . to have_sent_notification { |payload , headers |
1504+ exception = get_exception_from_payload ( payload )
1505+ expect ( exception [ "message" ] ) . to eq ( "大好き\n 大好き" )
1506+ }
1507+ end
1508+
1509+ it "leaves UTF-8 strings as-is" do
1510+ exception = ExceptionWithDetailedMessageButNoHighlight . new ( "Обичам те\n 大好き" )
1511+ expect ( exception . detailed_message . encoding ) . to be ( Encoding ::UTF_8 )
1512+
1513+ Bugsnag . notify ( exception )
1514+
1515+ expect ( Bugsnag ) . to have_sent_notification { |payload , headers |
1516+ exception = get_exception_from_payload ( payload )
1517+ expect ( exception [ "message" ] ) . to eq ( "detail about 'Обичам те\n 大好き'" )
1518+ }
1519+ end
1520+
1521+ it "handles UTF-16 strings" do
1522+ exception = ExceptionWithDetailedMessageReturningEncodedString . new ( "Обичам те\n 大好き" , Encoding ::UTF_16 )
1523+ expect ( exception . detailed_message . encoding ) . to be ( Encoding ::UTF_16 )
1524+
1525+ Bugsnag . notify ( exception )
1526+
1527+ expect ( Bugsnag ) . to have_sent_notification { |payload , headers |
1528+ exception = get_exception_from_payload ( payload )
1529+
1530+ # the exception message is converted to UTF-8 by the Cleaner
1531+ expect ( exception [ "message" ] ) . to eq ( "abc Обичам те\n 大好き xyz" )
1532+ }
1533+ end
1534+
1535+ it "handles Shift JIS strings" do
1536+ exception = ExceptionWithDetailedMessageReturningEncodedString . new ( "大好き\n 大好き" , Encoding ::Shift_JIS )
1537+ expect ( exception . detailed_message . encoding ) . to be ( Encoding ::Shift_JIS )
1538+
1539+ Bugsnag . notify ( exception )
1540+
1541+ expect ( Bugsnag ) . to have_sent_notification { |payload , headers |
1542+ exception = get_exception_from_payload ( payload )
1543+
1544+ # the exception message is converted to UTF-8 by the Cleaner
1545+ expect ( exception [ "message" ] ) . to eq ( "abc 大好き\n 大好き xyz" )
1546+ }
1547+ end
14861548 end
14871549
14881550 it "supports unix-style paths in backtraces" do
0 commit comments