Skip to content

Commit

Permalink
fix(CodePreviewCollectionViewCell): Correctly decode some legacy text…
Browse files Browse the repository at this point in the history
… encodings

Signed-off-by: Philippe Weidmann <[email protected]>
  • Loading branch information
PhilippeWeidmann committed Sep 24, 2024
1 parent 69ebdac commit 5fe4081
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion kDrive/UI/View/Files/Preview/CodePreviewCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ class CodePreviewCollectionViewCell: PreviewCollectionViewCell {
func configure(with file: File) {
do {
// Read file
let content = try String(contentsOf: file.localUrl)
let data = try Data(contentsOf: file.localUrl, options: .alwaysMapped)
var maybeString: NSString?

NSString.stringEncoding(for: data, convertedString: &maybeString, usedLossyConversion: nil)
guard let maybeString else {
throw DriveError.unknownError
}

let content = maybeString as String

// Display content
if file.extension == "md" || file.extension == "markdown" {
displayMarkdown(for: content)
Expand Down

0 comments on commit 5fe4081

Please sign in to comment.