You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2017/12/14 19:29:13 UTC

[GitHub] surajpindoria closed pull request #50: Fix opening of files in Windows Phone 8.

surajpindoria closed pull request #50: Fix opening of files in Windows Phone 8.
URL: https://github.com/apache/cordova-plugin-inappbrowser/pull/50
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/wp/InAppBrowser.cs b/src/wp/InAppBrowser.cs
index f5b7b1d5..969f287a 100644
--- a/src/wp/InAppBrowser.cs
+++ b/src/wp/InAppBrowser.cs
@@ -14,6 +14,7 @@
 
 using System;
 using System.Diagnostics;
+using System.Globalization;
 using System.IO;
 using System.Runtime.Serialization;
 using System.Windows;
@@ -239,7 +240,7 @@ private void ShowCordovaBrowser(string url)
                 return;
             }
 
-            var file = await GetFile(pathUri.AbsolutePath.Replace('/', Path.DirectorySeparatorChar));
+            var file = await GetFile(FixUrl(url));
             if (file != null)
             {
                 await Launcher.LaunchFileAsync(file);
@@ -250,6 +251,30 @@ private void ShowCordovaBrowser(string url)
             }
         }
 
+        private string FixUrl(string url)
+        {
+            const string IsolatedStorageProtocol = "x-wmapp0:/"; // NOTE: 1 slash, due to paths being screwed up (for example: x-wmapp:/tmp//test.doc, instead of x-wmapp://tmp/test.doc)
+            string DoubleSeparator = Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture) + Path.DirectorySeparatorChar;
+
+            // Remove x-wmapp0 protocol, making this a relative URL, keeping the original path
+            if (url.StartsWith(IsolatedStorageProtocol, StringComparison.OrdinalIgnoreCase))
+            {
+                url = url.Substring(IsolatedStorageProtocol.Length);
+            }
+
+            // Replace forward slashes with environment slashes + strip double slashes
+            url = url.Replace('/', Path.DirectorySeparatorChar);
+            while (url.IndexOf(DoubleSeparator) != -1)
+            {
+                url = url.Replace(DoubleSeparator, Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture);
+            }
+
+            // Remove trailing and leading path separator chars
+            url = url.Trim(Path.DirectorySeparatorChar);
+
+            return url;
+        }
+
         private async Task<StorageFile> GetFile(string fileName)
         {
             //first try to get the file from the isolated storage


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org