From b29d90be695c3a565e1df92c7bae4d89e2adcb00 2020-02-13 17:39:32
From: Matthias Bussonnier <bussonniermatthias@gmail.com>
Date: 2020-02-13 17:39:32
Subject: [PATCH] Backport PR #12122: Pop the last if path ends with slash

---

diff --git a/IPython/terminal/ptutils.py b/IPython/terminal/ptutils.py
index 4f21cb0..47fd6f4 100644
--- a/IPython/terminal/ptutils.py
+++ b/IPython/terminal/ptutils.py
@@ -42,6 +42,8 @@ def _elide(string, *, min_elide=30):
 
     object_parts = string.split('.')
     file_parts = string.split(os.sep)
+    if file_parts[-1] == '':
+        file_parts.pop()
 
     if len(object_parts) > 3:
         return '{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}'.format(object_parts[0], object_parts[1][0], object_parts[-2][-1], object_parts[-1])
diff --git a/IPython/terminal/tests/test_interactivshell.py b/IPython/terminal/tests/test_interactivshell.py
index 9651a22..6bacc8e 100644
--- a/IPython/terminal/tests/test_interactivshell.py
+++ b/IPython/terminal/tests/test_interactivshell.py
@@ -5,6 +5,7 @@
 
 import sys
 import unittest
+import os
 
 from IPython.core.inputtransformer import InputTransformer
 from IPython.testing import tools as tt
@@ -19,6 +20,10 @@ class TestElide(unittest.TestCase):
         _elide('concatenate((a1, a2, ...), axis') # do not raise
         _elide('concatenate((a1, a2, ..), . axis') # do not raise
         nt.assert_equal(_elide('aaaa.bbbb.ccccc.dddddd.eeeee.fffff.gggggg.hhhhhh'), 'aaaa.b…g.hhhhhh')
+        
+        test_string = os.sep.join(['', 10*'a', 10*'b', 10*'c', ''])
+        expect_stirng = os.sep + 'a' + '\N{HORIZONTAL ELLIPSIS}' + 'b' + os.sep + 10*'c'
+        nt.assert_equal(_elide(test_string), expect_stirng)
 
 
 class TestContextAwareCompletion(unittest.TestCase):