From 9f7aaa8ee4cbd8c36c5cfb6e55e5366be4ff238c Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 1 Oct 2019 18:46:56 -0700 Subject: [PATCH] Fix an issue where any diff which could possibly be rendered as Jupyter decided to render as Jupyter Summary: See PHI1468. Engine selection for diffs is currently too aggressive in trying to find a shared engine and will fall back a shared engine with a very low score, causing all ".json" files to render as Jupyter files. Only pick an engine as a difference engine by default if it's the highest-scoring engine for the new file. Test Plan: Viewed ".json" files and ".ipynb" files in a revision. Before, both rendered as Jupyter. Now, the former rendered as JSON and the latter rendered as Jupyter. Differential Revision: https://secure.phabricator.com/D20850 --- .../parser/DifferentialChangesetParser.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/applications/differential/parser/DifferentialChangesetParser.php b/src/applications/differential/parser/DifferentialChangesetParser.php index a485a787cb..6c4ed3d14f 100644 --- a/src/applications/differential/parser/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/DifferentialChangesetParser.php @@ -1718,7 +1718,8 @@ final class DifferentialChangesetParser extends Phobject { $viewer, $new_ref); - $shared_engines = array_intersect_key($old_engines, $new_engines); + $shared_engines = array_intersect_key($new_engines, $old_engines); + $default_engine = head_key($new_engines); foreach ($shared_engines as $key => $shared_engine) { if (!$shared_engine->canDiffDocuments($old_ref, $new_ref)) { @@ -1734,7 +1735,17 @@ final class DifferentialChangesetParser extends Phobject { $document_engine = null; } } else { - $document_engine = head($shared_engines); + // If we aren't rendering with a specific engine, only use a default + // engine if the best engine for the new file is a shared engine which + // can diff files. If we're less picky (for example, by accepting any + // shared engine) we can end up with silly behavior (like ".json" files + // rendering as Jupyter documents). + + if (isset($shared_engines[$default_engine])) { + $document_engine = $shared_engines[$default_engine]; + } else { + $document_engine = null; + } } if ($document_engine) {