Skip to content

Commit

Permalink
Fix crash when searching for ^$ regular expression
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed Mar 15, 2023
1 parent 4f1314b commit 5ed1b5f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Maccy/HistoryMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ class HistoryMenuItem: NSMenuItem {
let rangeLength = range.upperBound - range.lowerBound + 1
let highlightRange = NSRange(location: range.lowerBound, length: rangeLength)

attributedTitle.addAttribute(.font, value: highlightFont, range: highlightRange)
if Range(highlightRange, in: title) != nil {
attributedTitle.addAttribute(.font, value: highlightFont, range: highlightRange)
}
}

self.attributedTitle = attributedTitle
Expand Down
2 changes: 1 addition & 1 deletion Maccy/Preview/Preview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Preview: NSViewController {
applicationValueLabel.removeFromSuperview()
}

if textView.stringValue.count > maxTextSize {
if textView.stringValue.count > maxTextSize {
textView.stringValue = textView.stringValue.shortened(to: maxTextSize)
}

Expand Down
6 changes: 6 additions & 0 deletions MaccyTests/HistoryMenuItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ class HistoryMenuItemTests: XCTestCase {
XCTAssertEqual(menuItem.attributedTitle, nil)
}

func testHighlightInvalidRange() {
let menuItem = historyMenuItem("")
menuItem.highlight([0...0])
XCTAssertEqual(menuItem.attributedTitle?.string, "")
}

private func historyMenuItem(_ value: String?, application: String? = "com.apple.finder") -> HistoryMenuItem {
let content = HistoryItemContent(type: NSPasteboard.PasteboardType.string.rawValue,
value: value?.data(using: .utf8))
Expand Down

0 comments on commit 5ed1b5f

Please sign in to comment.