From 4152181c99251360eeddd8ec54795e4b8874d48e Mon Sep 17 00:00:00 2001 From: Martin Gonzalez Date: Tue, 22 Jul 2014 15:09:20 -0500 Subject: [PATCH] CB-6923 Adding support to handle relative paths Added support to resolve relative paths. When the path received is relative, it will combine and obtain a full path before it becomes proceced by IsolatedStorageFile and determine if exists. Two private methods were added to handle this, it won't affect the regular workflow if the path is absolute and it will combine it as usual. --- src/wp/File.cs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/wp/File.cs b/src/wp/File.cs index 07143b92a..0f2fe50cf 100644 --- a/src/wp/File.cs +++ b/src/wp/File.cs @@ -1501,6 +1501,35 @@ private void CopyDirectory(string sourceDir, string destDir, IsolatedStorageFile } } + private string RemoveExtraSlash(string path) { + if (path.StartsWith("//")) { + path = path.Remove(0, 1); + path = RemoveExtraSlash(path); + } + return path; + } + + private string ResolvePath(string parentPath, string path) + { + string absolutePath = null; + + if (path.Contains("..")) + { + if (parentPath.Length > 1 && parentPath.StartsWith("/") && parentPath !="/") + { + parentPath = RemoveExtraSlash(parentPath); + } + + string fullPath = Path.GetFullPath(Path.Combine(parentPath, path)); + absolutePath = fullPath.Replace(Path.GetPathRoot(fullPath), @"//"); + } + else + { + absolutePath = Path.Combine(parentPath + "/", path); + } + return absolutePath; + } + private void GetFileOrDirectory(string options, bool getDirectory) { FileOptions fOptions = new FileOptions(); @@ -1539,13 +1568,13 @@ private void GetFileOrDirectory(string options, bool getDirectory) try { - path = Path.Combine(fOptions.FullPath + "/", fOptions.Path); + path = ResolvePath(fOptions.FullPath, fOptions.Path); } catch (Exception) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ENCODING_ERR), callbackId); return; - } + } using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication()) {