Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions GitUpKit/Interface/GIFunctions-Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ - (void)testHighlightingRange {
XCTAssertEqual(addedRange.location, 3);
XCTAssertEqual(addedRange.length, 2);
}
{
// Fix for issue #2740
const char* before = "中文命名.md";
const char* after = "中文命名1.md";
GIComputeHighlightRanges(before, strlen(before), [[NSString stringWithUTF8String:before] length], &deletedRange, after, strlen(after), [[NSString stringWithUTF8String:after] length], &addedRange);
XCTAssertEqual(deletedRange.location, 4);
XCTAssertEqual(deletedRange.length, 0);
XCTAssertEqual(addedRange.location, 4);
XCTAssertEqual(addedRange.length, 1);
}
}

@end
16 changes: 8 additions & 8 deletions GitUpKit/Interface/GIFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ void GIComputeHighlightRanges(const char* deletedBytes, NSUInteger deletedCount,
}
if (remaining == 0) {
unsigned char byte = *(unsigned char*)deletedMin;
if (TEST_BITS(byte, 0b11000000)) {
remaining = 2;
} else if (TEST_BITS(byte, 0b11100000)) {
remaining = 3;
} else if (TEST_BITS(byte, 0b11110000)) {
remaining = 4;
if (TEST_BITS(byte, 0b11111100)) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 and 6 technically aren't in the standard but might as well keep them 🤷‍♂️

remaining = 6;
} else if (TEST_BITS(byte, 0b11111000)) {
remaining = 5;
} else if (TEST_BITS(byte, 0b11111100)) {
remaining = 6;
} else if (TEST_BITS(byte, 0b11110000)) {
remaining = 4;
} else if (TEST_BITS(byte, 0b11100000)) {
remaining = 3;
} else if (TEST_BITS(byte, 0b11000000)) {
remaining = 2;
} else {
XLOG_DEBUG_CHECK(!(byte & (1 << 7)));
remaining = 1;
Expand Down