Skip to content

Commit 990f835

Browse files
authored
Release v6.26.4
2 parents 13040d4 + 50282e3 commit 990f835

5 files changed

Lines changed: 99 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
Changelog
22
=========
33

4+
## v6.26.4 (25 March 2024)
5+
6+
### Fixes
7+
8+
* Fix Unicode encoding issues when using `Exception#detailed_message` (Ruby 3.2+)
9+
| [#817](https://github.com/bugsnag/bugsnag-ruby/pull/817)
10+
* Fix compatibility with Ruby 3.4-dev
11+
| [#815](https://github.com/bugsnag/bugsnag-ruby/pull/815)
12+
| [k0kubun](https://github.com/k0kubun)
13+
414
## v6.26.3 (24 January 2024)
515

16+
### Fixes
17+
618
* Handle mailto links in `Cleaner#clean_url`
719
| [#813](https://github.com/bugsnag/bugsnag-ruby/pull/813)
820

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.26.3
1+
6.26.4

lib/bugsnag/report.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,15 @@ def error_message(exception, class_name)
466466
exception.detailed_message
467467
end
468468

469+
# the string returned by 'detailed_message' defaults to 'ASCII_8BIT' but
470+
# is actually UTF-8 encoded; we can't convert the encoding normally as its
471+
# internal encoding doesn't match its actual encoding
472+
message.force_encoding(::Encoding::UTF_8) if message.encoding == ::Encoding::ASCII_8BIT
473+
469474
# remove the class name to be consistent with Exception#message
470-
message.sub(" (#{class_name})", '')
475+
message.sub!(" (#{class_name})".encode(message.encoding), "") rescue nil
476+
477+
message
471478
end
472479

473480
def generate_raw_exceptions(exception)

lib/bugsnag/stacktrace.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Bugsnag
44
module Stacktrace
55
# e.g. "org/jruby/RubyKernel.java:1264:in `catch'"
6-
BACKTRACE_LINE_REGEX = /^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$/
6+
BACKTRACE_LINE_REGEX = /^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in [`']([^']+)')?$/
77

88
# e.g. "org.jruby.Ruby.runScript(Ruby.java:807)"
99
JAVA_BACKTRACE_REGEX = /^(.*)\((.*)(?::([0-9]+))?\)$/

spec/report_spec.rb

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ def detailed_message
4040
end
4141
end
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+
4354
shared_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

Comments
 (0)