From 88cbbc86b84984946b80f6dd18e5a6a88b47f936 Mon Sep 17 00:00:00 2001
From: Tom Needham <needham.thomas@gmail.com>
Date: Mon, 2 Jul 2012 19:06:40 +0000
Subject: [PATCH] Text editor: Always use UTF-8 to keep Ace happy.

---
 apps/files_texteditor/ajax/loadfile.php | 1 +
 apps/files_texteditor/ajax/savefile.php | 1 +
 2 files changed, 2 insertions(+)

diff --git a/apps/files_texteditor/ajax/loadfile.php b/apps/files_texteditor/ajax/loadfile.php
index c263306e719..5a5affa46be 100644
--- a/apps/files_texteditor/ajax/loadfile.php
+++ b/apps/files_texteditor/ajax/loadfile.php
@@ -43,6 +43,7 @@ if(!empty($filename))
 	{
 		$mtime = OC_Filesystem::filemtime($path);
 		$filecontents = OC_Filesystem::file_get_contents($path);
+		$filecontents = iconv(mb_detect_encoding($filecontents), "UTF-8", $filecontents);
 		OCP\JSON::success(array('data' => array('filecontents' => $filecontents, 'write' => 'false', 'mtime' => $mtime)));	
 	}	
 } else {
diff --git a/apps/files_texteditor/ajax/savefile.php b/apps/files_texteditor/ajax/savefile.php
index f789112d7d7..961db7105e3 100644
--- a/apps/files_texteditor/ajax/savefile.php
+++ b/apps/files_texteditor/ajax/savefile.php
@@ -48,6 +48,7 @@ if($path != '' && $mtime != '' && $filecontents)
 		// Save file
 		if(OC_Filesystem::is_writable($path))
 		{
+			$filecontents = iconv(mb_detect_encoding($filecontents), "UTF-8", $filecontents);
 			OC_Filesystem::file_put_contents($path, $filecontents);
 			// Clear statcache
 			clearstatcache();
-- 
GitLab