4

I've created an Azure C# HTTP triggered function with a route url: subscriptions/{token}/t. It works fine for urls such as subscriptions/blah/t but it fails with a 404 for parameters that contain encoded slashes: subscriptions/blah%2fblah/t. Any way around this ?

Before we get into debates, {token} is a URL encoded Base64 string which will naturally contain slashes.

marius-O
  • 395
  • 3
  • 15

2 Answers2

2

This issue seems to persist. I found out that it can be resolved by double-escaping the string, that is, applying escaping recursively two times.

token = escape(escape(token));

In .NET you can use URI.EsacpeDataString()
In JS you can use encodeURIComponent()

Note, that single escaping does not work reliably with Azure functions

Jan D.
  • 36
  • 3
0

but it fails with a 404 for parameters that contain encoded slashes: subscriptions/blah%2fblah/t.

It is make sense because 'subscriptions/blah%2fblah/t' is equal to 'subscriptions/blah/blah/t'. I suggest you define your own encode rule for slashes. For example, you could convert all the slashes to '[[-]]'. Your token will be like this 'subscriptions/blah[[-]]blah/t'. After received the token, you could convert the special characters back.

token = token.Replace("[[-]]", "/");
Amor
  • 8,325
  • 2
  • 19
  • 21
  • 1
    Agreed, but what's the purpose of encoding the parameter other than making sure it hits my action/function as it is (with slashes ...) ? – marius-O Sep 04 '17 at 14:15
  • How many slashes in your token? Is it a fix size? If yes, you could modify your route URL to match it. Otherwise, you need to encode your token using your own ways. – Amor Sep 05 '17 at 01:11
  • Any update? If you have further questions, please feel free to let me know. – Amor Sep 06 '17 at 02:43
  • I've ended up encoding the slashes and equals to something less offending, I'll do a report in the azure forums though, that doesn't sound right... – marius-O Sep 07 '17 at 05:57