Skip to content

Commit

Permalink
GUI: Fix unicode rendering of attributed messages (#1351)
Browse files Browse the repository at this point in the history
Also added a test to stop this from happening again
  • Loading branch information
russellhancox authored May 15, 2024
1 parent 8e1e155 commit 67883c5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Source/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,16 @@ santa_unit_test(
name = "SNTBlockMessageTest",
srcs = ["SNTBlockMessageTest.m"],
deps = [
":SNTBlockMessage",
":SNTBlockMessage_SantaGUI",
":SNTConfigurator",
":SNTFileAccessEvent",
":SNTStoredEvent",
":SNTSystemInfo",
"@OCMock",
],
sdk_frameworks = [
"AppKit",
],
)

santa_unit_test(
Expand Down
6 changes: 5 additions & 1 deletion Source/common/SNTBlockMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ + (NSAttributedString *)formatMessage:(NSString *)message {

#ifdef SANTAGUI
NSData *htmlData = [fullHTML dataUsingEncoding:NSUTF8StringEncoding];
return [[NSAttributedString alloc] initWithHTML:htmlData documentAttributes:NULL];
NSDictionary *options = @{
NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute : @(NSUTF8StringEncoding),
};
return [[NSAttributedString alloc] initWithHTML:htmlData options:options documentAttributes:NULL];
#else
NSString *strippedHTML = [self stringFromHTML:fullHTML];
if (!strippedHTML) {
Expand Down
6 changes: 6 additions & 0 deletions Source/common/SNTBlockMessageTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ - (void)setUp {
OCMStub([self.mockSystemInfo serialNumber]).andReturn(@"my_s");
}

- (void)testFormatMessage {
NSString *input = @"Testing with somé Ünicode çharacters";
NSAttributedString *got = [SNTBlockMessage formatMessage:input];
XCTAssertEqualObjects([got string], input);
}

- (void)testEventDetailURLForEvent {
SNTStoredEvent *se = [[SNTStoredEvent alloc] init];

Expand Down

0 comments on commit 67883c5

Please sign in to comment.