Windows Phone deep links are incorrectly encoded

Suppose I have a Windows Phone app capable of handling deep links using the "my-app:" moniker. Given the following link:

my-app: // do / stuff / artist = Macklemore% 20% 26% 20Ryan% 20Lewis & test = 1

We can see two query string parameters: artist = "Macklemore & Ryan Lewis" and test = "1" .

If I create a web page with this link on it and open the page in Internet Explorer on the phone, this is what gets into the UriMapper application:

/protocol? EncodedLaunchUri = my-application% 3A% 2F% 2Fdo% 2Fstuff% 2F% 3Fartist% 3DMacklemore% 20% 26% 20Ryan% 20Lewis% 26test% 3D1

So it seems that not one of the encoded % values ​​has been re-encoded, but still it encoded & immediately before the test parameter ...

It seems to me that this is a platform error, because we will not be able to distinguish between the characters and the characters that we receive on UriMapper!

So the question is, does anyone know a way to use coded ampersands (% 26) in a Windows Phone deep link?

+4
source share
1 answer

I suspect the problem may be too low to access any of the public APIs.

As a starting point, I realized that we have at our disposal (and this will not require changes on the user side), which allows us to detect where the & signs are. From this, we can determine if & part of the value or query string delimiter. If the latter, we replace it with a random symbol and break it into this symbol.

 Regex rx = new Regex(@"(\b&.*?)="); 

The above regex matches only & , followed by = (so it will match &test= below, but not Macklemore & Ryan Lewis ).

Then we replace all instances of & that are matched by the above expression with a random character that will not be used elsewhere. In this example, I just used | .

 string mapperInput = @"Protocol?encodedLaunchUri=my-app://do/stuff/?artist=Macklemore & Ryan Lewis&test=1"; string final = rx.Replace(mapperInput, new MatchEvaluator( new Func<Match, string>(x => x.Value.Replace('&', '|')) )); 

Then we take this result and put it in the collection.

 //skip 2 because the first two matches include the protocol section var values = final.Split(new char[] { '?', '|' }).Skip(2).ToArray(); 

The values array now contains two elements (which can be iterated and placed in the Key-Value dictionary for access)

 artist=Macklemore & Ryan Lewis test=1 

This had to be tested with various inputs that include characters, but from a quick test, it seemed like normal.

+2
source

Source: https://habr.com/ru/post/1494740/


All Articles