'Typescript \n is replaced with %0A
I'm creating a custom Azure pipeline task using Typescript.
I got these lines:
var errorsAndWarnings = await getBuildErrors(pipelineRunId, true);
tl.setResult(tl.TaskResult.Succeeded, "Finished Service Operation\n" + errorsAndWarnings);
The value of errorsAndWarnings is "No Errors". So what I expected to see is:
Finished Service Operation
No Errors
But what I actually got was:
Finished Service Operation%0ANo Errors
How can I make the \n create a new line in the string?
Solution 1:[1]
You can get the ‘new line’ character by a conversion from its percent-encoded (Uri) value ‘%0A’ via decodeUriComponent(‘Uri value’) expression.
decodeUriComponent('%0A')
Instead of initializing a variable, you use decodeUriComponent(…) directly in the replace(…) expression. The example below will replace new lines with a semicolon.
replace(outputs('Compose'),decodeUriComponent('%0A'),';')
some files created in Windows use \r\n instead of just \n as the ‘new line’ value. If you end up with \r in your string in place of the new lines, try to replace the whole \r\n substring:
decodeUriComponent('%0D%0A')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kangcheng Jin-MSFT |
