Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Suggestion: escape file path JSON file #52

Closed
jeanfrancoislarente opened this issue Nov 21, 2017 · 9 comments
Closed

Suggestion: escape file path JSON file #52

jeanfrancoislarente opened this issue Nov 21, 2017 · 9 comments

Comments

@jeanfrancoislarente
Copy link

jeanfrancoislarente commented Nov 21, 2017

Hello,

I'm trying to use Replace Tokens to set a file path in a .json file.
My token is @@assets.root@@ and my variable has a normal file path. If this wasn't a .json file everything behaves as it should. However as you know in json the paths need to be escaped.

C:\my-path needs to be c:\\my-path.

Just hoping that this would make it in future versions (logic to escape paths when target is .json extension).

@qetza
Copy link
Owner

qetza commented Nov 21, 2017

Hi Jean-Francois,
The task doesn't do any analysis on the file type or the values but only plain text parsing and replace so i don't see how to add this request.

Could you escape the value in the variable directly?

@jeanfrancoislarente
Copy link
Author

Problem is I use built-in VSTS variables (such as $(System.ArtifactsDirectory) ) as part of my variable value which itself isn't escaped.

My workaround was to create a PowerShell task to set those variables in my .json file - but that defeats the purpose of (trying) to use tokens and a nice extension like this one.

@samuelhl
Copy link

Hi @jeanfrancoislarente

I'm curious as to how exactly you used a PowerShell task for this as I've run into the exact same issue using JSONs on TFS2017. If you could go into a bit more detail on your workaround that would be great.

Thanks.

@jeanfrancoislarente
Copy link
Author

I brute forced it - I just used powershell to explicitly take the parameters and replace them where they need to be set - there is no magical token replacement.

@samuelhl
Copy link

OK, thanks for the reply.

@qetza
Copy link
Owner

qetza commented Feb 27, 2018

Hi,
Sorry i didn't replied earlier, one solution if you want to use tokens and do escaping would be to:

  • use a powershell task to get your variables values, escape them and create new variables with the escaped values
  • use the replace token task with token names based on the new variable names

This can be done using vsts agent commands (https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md)

@qetza
Copy link
Owner

qetza commented Mar 4, 2018

Hi @jeanfrancoislarente and @samuelhl,
I've been thinking and here is a proposal of evolution of the task

  • add advance parameters Escape character and Characters to escape
  • when reading a variable value, if the above parameters are set, the task will replace any character in Characters to escape with the character prefixed with Escape character before replacing the token.

So if you put \ as escape character and \" as characters to escape it should work in your json files.

Would this evolution work for you?

@qetza qetza reopened this Mar 4, 2018
@jeanfrancoislarente
Copy link
Author

I imagine that would work?
No matter what the scenario is, "" should become "\" in a .json target file

@qetza
Copy link
Owner

qetza commented Mar 6, 2018

I just released v2.3.0 of the task which includes the 2 parameters to allow escaping characters.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants