microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.47k stars 2.61k forks source link

XML variable substitution - handling special characters problem #4001

Closed ghost closed 7 years ago

ghost commented 7 years ago

XML variable substitution - handling special characters problem

When I use IIS Web App Deploy (Deployment Groups) and XML variable substitution to modify the web.config file I see that the string in the output file is different from the input. In my case I have this connectionstring that I specify under Variables when creating a new Release definition. The connectionstring should be updated in the web.config in the deployed web app:

Data Source=xxxx-xxxxx;Initial Catalog=xxxxxxxx;User Id=xxxxxxUser; password='E~FU:5&?77WY3wRU#:'

but this is changed to

Data Source=xxxx-xxxxx;Initial Catalog=xxxxxxxx;User Id=xxxxxxUser; password='E~FU:5&?77WY3wRU#:'

So it seams like this feature is not able to handle special characters?

also when I test the same string that you have inside vsts-tasks/Tasks/Common/webdeployment-common/Tests/L1XmlVarSub.ts

This string: Url=https://primary;Database=db1;ApiKey=11111111-1111-1111-1111-111111111111;Failover = {Url:'https://secondary', ApiKey:'11111111-1111-1111-1111-111111111111'}

is changed to: Url=https://primary;Database=db1;ApiKey=11111111-1111-1111-1111-111111111111;Failover = {Url:'https://secondary', ApiKey:'11111111-1111-1111-1111-111111111111'}

vincent1173 commented 7 years ago

@smd11 , thanks for reporting the issue. This issue was fixed in 3.2.* version of the task. Can you please share the debug logs (by setting system.debug=true) and the version of the task ?

samidieb commented 7 years ago

@vincentdass the task that I'm working with is IIS WebApp Deploy(Preview) that is related to the new Deployment Groups feature. The logs shoes that version of the task is 0.0.14. Here is the debug log from running the task: ` 5_IIS Web App Deploy (Preview).zip

`

and here is the output web.config file: Web.config.zip

Thanks

vincent1173 commented 7 years ago

@smd11 , @samidieb . Sorry for the wrong info. The issue is resolved and the fix will be available in a week or two with 0.0.15 task version.

vincent1173 commented 7 years ago

Deployment in currently in progress and the fix will be available in a week or two.

k-ljung commented 7 years ago

@vincentdass I still have this problem on some .config file. Currently I'm running Umbraco CMS with the uSync add-on and it creates a lots of config files. The IIS Web App Deploy(Preview) task is trying to substitute variables in all of this files.

I'm running version 0.0.21 of the task, the uSync files is stored under a subfolder uSync\data in the root.

I can send over log files in private.

vincent1173 commented 7 years ago

@k-ljung , Please share the debug logs (set variable system.debug=true and rerun the release) to RM_Customer_Queries@Microsoft.com ?

k-ljung commented 7 years ago

@vincentdass, done

frankfuu commented 6 years ago

hi @vincentdass

I'm experiencing a similar issue Azure App Service Deploy 3.3.24. It says XML variable substitution applied successfully but has weird behavior.

2017-11-08T05:27:48.9925301Z ##[section]Starting: Deploy My App
2017-11-08T05:27:49.0237840Z ==============================================================================
2017-11-08T05:27:49.0237840Z Task         : Azure App Service Deploy
2017-11-08T05:27:49.0237840Z Description  : Update Azure WebApp Services On Windows, Web App On Linux with built-in images or docker containers, ASP.NET, .NET Core, PHP, Python or Node based Web applications, Function Apps, Mobile Apps, Api applications, Web Jobs using Web Deploy / Kudu REST APIs
2017-11-08T05:27:49.0237840Z Version      : 3.3.24
2017-11-08T05:27:49.0237840Z Author       : Microsoft Corporation
2017-11-08T05:27:49.0237840Z Help         : [More Information](https://aka.ms/azurermwebdeployreadme)
2017-11-08T05:27:49.0237840Z ==============================================================================
2017-11-08T05:27:52.1175930Z Got connection details for Azure App Service:'is-ff-myapp'
2017-11-08T05:27:55.8832924Z XML variable substitution applied successfully.

Before XML variable substitution my Web.config file looks like this

<!--add key="Chargify.Something.Values" value="499101,536997,594079,1005146" />
    <add key="Chargify.SomethingElse.PublicExcludes" value="1005146" />
    <add key="Chargify.SomethingSomething.ID" value="3900550" />        
    <add key="Chargify.Base.Url" value="https://investsmart.chargify.com" />-->

After XML variable substitution my Web.config file looks like this

<add key="Chargify.Base.Url" value="https://mycompany.chargify.com" />--&gt;

To reproduce this, open a web.config (or any XML ) file, select more than 1 line then use Visual Studio's multi line comment (CTRL+K, CTRL+C) shortcut.

vincent1173 commented 6 years ago

@frankfuu , thanks for reaching out. We have an active thread on this issue and planned for hot-fix. Please follow the above thread for further updates.

frankfuu commented 6 years ago

Hi @vincentdass, thanks for the quick response

MichalKoscielniak commented 6 years ago

Hi @vincentdass ,

I have just started getting the same issue. I have a setting in web.config which is using ampersand. <add key="DatabaseConnectionString" value="MY_DB_DATA&amp;ssl=true" />

In the release definition i have a variable DatabaseConnectionString with a secret value. The variable's value stores plain connection string ( without escaping the ampersand ) i.e. MY_DB_DATA&ssl=true

Last time i did a release ( around a month ago ) it was working - it replaced the web.config file with escaped ampersand so this: MY_DB_DATA&ssl=true became this: MY_DB_DATA&amp;ssl=true

Today it does not work that way - it replaces the whole text without escaping it, and therefor making web.config file invalid xml. Is it indended ? I think it shouldn't work like that - i'm using this variable for other tasks too where it can't be escaped.

I would like to know which behaviours is the expected one.

Task details below:

2018-04-19T11:32:31.5328700Z Task : Azure App Service Deploy 2018-04-19T11:32:31.5329990Z Description : Update Azure WebApp Services On Windows, Web App On Linux with built-in images or docker containers, ASP.NET, .NET Core, PHP, Python or Node based Web applications, Function Apps, Mobile Apps, Api applications, Web Jobs using Web Deploy / Kudu REST APIs 2018-04-19T11:32:31.5332866Z Version : 3.3.46 2018-04-19T11:32:31.5334390Z Author : Microsoft Corporation 2018-04-19T11:32:31.5336355Z Help : More Information 2018-04-19T11:32:31.5337408Z

vincent1173 commented 6 years ago

@MichalKoscielniak , ideally there should be no alteration made to the variable value set by the user. This was a bug and we fixed it. This caused the regression in your case. Please change your variable value to required value (MY_DB_DATA&amp;ssl=true)

Sarafian commented 5 years ago

@MichalKoscielniak , ideally there should be no alteration made to the variable value set by the user. This was a bug and we fixed it. This caused the regression in your case. Please change your variable value to required value (MY_DB_DATA&amp;ssl=true)

I think this is a wrong advice, because it moves the responsibility of transforming the data into variable container. For example, what if the content of the variable is going to be used both in JSON and XML? The content should be correct and should be adjusted/escaped based on the target file type. This is something that is implicit when working with XMLs.

Sjark commented 4 years ago

I agree with @Sarafian , you should preferably have the correct value (with '&' not '&amp;') in your variable, then it should be escaped correctly by the xml variable substitution.

If you have to do the escape in the variable itself, you have to have one variable for xml and another variable for json and other config files that don't understand that '&amp;' == '&'