stephaneey / azure-apim-extension

Full Azure API Management suite and more VSTS extension
MIT License
66 stars 48 forks source link

Escaping policies using double quotes (") #28

Closed anton-g closed 5 years ago

anton-g commented 5 years ago

Hi!

We've run in to an issue when we wanted to use the policy template when creating/updating an API, but the policy contains a double quote ("). Since the extension replaces all " with ' in the policy it breaks when sending to APIM.

Maybe it would be better to escape the quotes instead of replacing them with single quotes, but I'm not a powershell guy so might be unaware of some limitation :)

Here is a very basic example policy:

<policies>
    <inbound>
        <set-backend-service base-url='@(context.Api.ServiceUrl.ToString().Replace("https", "http"))' />
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>
stephaneey commented 5 years ago

Hi Anton,

I'll have a look at it over the weekend since I already planned a new release.

Thanks Best Regards

anton-g commented 5 years ago

I discovered that you can escape quotes by replacing them with &quot;, so maybe that could work here as well :) Thanks for a great extension!

stephaneey commented 5 years ago

Hello anton, I've indeed used the htmlentity " and it seems it's working allright :)

jaq316 commented 5 years ago

We're also experiencing this issue in the Set or update an operation policy task. Can you point me in the right direction here? &quot; doesn't seem to work

ghost commented 5 years ago

Has the fix for this been released yet? We've tried using the &quot; but it's still not totally working.

ghost commented 5 years ago

Also getting the following errors. Is this an issue with my policy or an issue with the extension?

<set-variable name="x-sub" value="@(context.Request.Headers[&quot;Authorization&quot;].First().Split(&quot; &quot;)[1].AsJwt()?.Claims[&quot;sub&quot;].FirstOrDefault())" /> The set-variable tag is line 25. Error: @{code=ValidationError; target=set-variable; message=Error in element 'set-variable' on line 24, column 18: Argument 1: cannot convert from 'string' to 'char'}

<set-header name="SecurityId" exists-action="override">
        <value>@((string)context.Variables["x-sub"])</value>
</set-header>

The opening set-header tag is line 27. Error: @{code=ValidationError; target=set-header; message=Error in element 'set-header' on line 27, column 18: Too many characters in character literal}

stephaneey commented 4 years ago

Hi @anton-g, @amyhre16 , @DavidFreetly,

If I copy paste the set backend url policy "as is", it works like a charm so, I can't reproduce the issue.

Best Regards