@@ -941,15 +941,16 @@ public function getMonacoModel(SubmissionFile $file): string
941941 }
942942 $ this ->renderedSources [$ file ->getSubmitfileid ()] = true ;
943943
944+ $ source = mb_check_encoding ($ file ->getSourcecode (), 'UTF-8 ' ) ? $ file ->getSourcecode () : "Could not display binary file " ;
944945 return sprintf (
945946 <<<JS
946947monaco.editor.createModel(
947- "%s" ,
948+ %s ,
948949 undefined,
949950 monaco.Uri.parse("diff/%d/%s")
950951);
951952JS ,
952- $ this ->twig -> getRuntime (EscaperRuntime::class)-> escape ( $ file -> getSourcecode () , 'js ' ),
953+ $ this ->serializer -> serialize ( $ source , 'json ' ),
953954 $ file ->getSubmitfileid (),
954955 $ file ->getFilename (),
955956 );
@@ -968,7 +969,7 @@ public function showDiff(string $editorId, string $diffId, SubmissionFile $newFi
968969 const models = %s;
969970 require(['vs/editor/editor.main'], () => {
970971 const modifiedModel = %s;
971- initDiffEditorTab(editorId, diffId, rank, models, modifiedModel)
972+ initDiffEditorTab(editorId, diffId, rank, models, modifiedModel);
972973 });
973974});
974975</script>
@@ -977,11 +978,12 @@ public function showDiff(string $editorId, string $diffId, SubmissionFile $newFi
977978 $ others = [];
978979 foreach ($ otherFiles as $ submissionId => $ files ) {
979980 foreach ($ files as $ f ) {
980- if ($ f ->getFilename () == $ newFile ->getFilename ()) {
981+ // TODO: this renames the old file to multiple files, need more data in `showDiff`.
982+ if (($ newFile ->getRank () === 1 && count ($ files ) === 1 ) || ($ f ->getFilename () == $ newFile ->getFilename ())) {
981983 // TODO: add `tag` containing `previous` / `original`
982984 $ others [$ submissionId ] = [
983985 'filename ' => $ f ->getFilename (),
984- 'source ' => $ f ->getSourcecode (),
986+ 'source ' => mb_check_encoding ( $ f ->getSourcecode (), ' UTF-8 ' ) ? $ f -> getSourcecode () : " Could not display binary file " ,
985987 ];
986988 }
987989 }
0 commit comments