Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bug with backslashed windows paths

  • Loading branch information...
commit e741a4a6bc7aa592022d8cdbf0b4a981d3e284f2 1 parent 0e79b9b
@joonty authored
Showing with 61 additions and 19 deletions.
  1. +15 −10 plugin/python/vdebug/util.py
  2. +46 −9 tests/test_util_filepath.py
View
25 plugin/python/vdebug/util.py
@@ -1,7 +1,7 @@
import vdebug.opts
import vdebug.log
import vim
-import sys
+import re
import urllib
class Keymapper:
@@ -52,6 +52,8 @@ def unmap(self):
vim.command("map %s" % mapping)
class FilePath:
+ is_win = False
+
"""Normalizes a file name and allows for remote and local path mapping.
"""
def __init__(self,filename):
@@ -59,12 +61,15 @@ def __init__(self,filename):
len(filename) == 0:
raise FilePathError, "Missing or invalid file name"
filename = urllib.unquote(filename)
- if filename.startswith('file:///'):
- if sys.platform == "win32":
- """ remove prefix till the drive letter """
- filename = filename[8:]
- else:
- filename = filename[7:]
+ if filename.startswith('file://'):
+ filename = filename[7:]
+
+ p = re.compile('^[a-zA-Z]:')
+ if p.match(filename):
+ self.is_win = True
+ if filename[2] == "\\":
+ filename = filename.replace("\\","/")
+
self.local = self._create_local(filename)
self.remote = self._create_remote(filename)
@@ -76,7 +81,7 @@ def _create_local(self,f):
ret = f
if vdebug.opts.Options.isset('path_maps'):
for remote, local in vdebug.opts.Options.get('path_maps', dict).items():
- if ret.startswith(remote):
+ if remote in ret:
vdebug.log.Log("Replacing remote path (%s) " % remote +\
"with local path (%s)" % local ,\
vdebug.log.Logger.DEBUG)
@@ -93,13 +98,13 @@ def _create_remote(self,f):
if vdebug.opts.Options.isset('path_maps'):
for remote, local in vdebug.opts.Options.get('path_maps', dict).items():
- if ret.startswith(local):
+ if local in ret:
vdebug.log.Log("Replacing local path (%s) " % local +\
"with remote path (%s)" % remote ,\
vdebug.log.Logger.DEBUG)
ret = ret.replace(local,remote)
break
- return ret
+ return "file://"+ret
def as_local(self,quote = False):
if quote:
View
55 tests/test_util_filepath.py
@@ -21,10 +21,15 @@ def test_remote_prefix(self):
file = FilePath(prefix+filename)
self.assertEqual(filename,file.as_local())
+ def test_quoted(self):
+ quoted = "file:///home/user/file%2etcl"
+ file = FilePath(quoted)
+ self.assertEqual("/home/user/file.tcl",file.as_local())
+
def test_as_remote(self):
filename = "/home/user/some/path"
file = FilePath(filename)
- self.assertEqual(filename,file.as_remote())
+ self.assertEqual("file://"+filename,file.as_remote())
def test_eq(self):
filename = "/home/user/some/path"
@@ -67,24 +72,56 @@ def test_add_reverse(self):
def test_empty_file_raises_error(self):
self.assertRaises(FilePathError,FilePath,"")
-def RemotePathTest(self):
+class RemotePathTest(unittest.TestCase):
def setUp(self):
- vdebug.opts.Options.set({'path_maps':{'/remote1/':'/local1/', '/remote2/':'/local2'}})
+ vdebug.opts.Options.set({'path_maps':{'/remote1/':'/local1/', '/remote2/':'/local2/'}})
def test_as_local(self):
filename = "/remote1/path/to/file"
file = FilePath(filename)
- self.assertEqual("/local1/path/to/file",file)
+ self.assertEqual("/local1/path/to/file",file.as_local())
filename = "/remote2/path/to/file"
file = FilePath(filename)
- self.assertEqual("/local2/path/to/file",file)
+ self.assertEqual("/local2/path/to/file",file.as_local())
- def test_as_remote(self):
+ def test_as_local_with_uri(self):
+ filename = "file:///remote1/path/to/file"
+ file = FilePath(filename)
+ self.assertEqual("/local1/path/to/file",file.as_local())
+
+ filename = "file:///remote2/path/to/file"
+ file = FilePath(filename)
+ self.assertEqual("/local2/path/to/file",file.as_local())
+
+ def test_as_local_does_nothing(self):
+ filename = "/the/remote/path/to/file"
+ file = FilePath(filename)
+ self.assertEqual("/the/remote/path/to/file",file.as_local())
+
+ def test_as_remote_with_unix_paths(self):
filename = "/local1/path/to/file"
file = FilePath(filename)
- self.assertEqual("/remote1/path/to/file",file)
+ self.assertEqual("file:///remote1/path/to/file",file.as_remote())
+
+ filename = "file:///local2/path/to/file"
+ file = FilePath(filename)
+ self.assertEqual("file:///remote2/path/to/file",file.as_remote())
+
+ def test_as_remote_with_win_paths(self):
+ filename = "C:/local1/path/to/file"
+ file = FilePath(filename)
+ self.assertEqual("file://C:/remote1/path/to/file",file.as_remote())
+
+ filename = "C:/local2/path/to/file"
+ file = FilePath(filename)
+ self.assertEqual("file://C:/remote2/path/to/file",file.as_remote())
+
+ def test_as_remote_with_backslashed_win_paths(self):
+ filename = "C:\\local1\\path\\to\\file"
+ file = FilePath(filename)
+ self.assertEqual("file://C:/remote1/path/to/file",file.as_remote())
- filename = "/local2/path/to/file"
+ filename = "C:\\local2\\path\\to\\file"
file = FilePath(filename)
- self.assertEqual("/remote2/path/to/file",file)
+ self.assertEqual("file://C:/remote2/path/to/file",file.as_remote())
Please sign in to comment.
Something went wrong with that request. Please try again.