diff --git a/bower.json b/bower.json
index 52138a7f30..58e237b26b 100644
--- a/bower.json
+++ b/bower.json
@@ -5,7 +5,7 @@
     "backbone": "components/backbone#~1.2",
     "bootstrap": "bootstrap#~3.4",
     "bootstrap-tour": "0.9.0",
-    "codemirror": "components/codemirror#~5.48.4",
+    "codemirror": "components/codemirror#~5.51.0",
     "create-react-class": "https://cdn.jsdelivr.net/npm/create-react-class@15.6.3/create-react-class.min.js",
     "es6-promise": "~1.0",
     "font-awesome": "components/font-awesome#~4.7.0",
diff --git a/notebook/static/base/js/utils.js b/notebook/static/base/js/utils.js
index 54a2bd0d4f..1d8a9d010e 100644
--- a/notebook/static/base/js/utils.js
+++ b/notebook/static/base/js/utils.js
@@ -754,7 +754,7 @@ define([
         // .mime
         var info = (mode && mode.mode && mode.mime && mode) ||
             CodeMirror.findModeByName(modename) ||
-            CodeMirror.findModeByExtension(modename.split(".").slice(-1)) ||
+            CodeMirror.findModeByExtension(modename.split(".").slice(-1)[0]) ||
             CodeMirror.findModeByMIME(modename) ||
             {mode: modename, mime: modename};