Escape characters

Hi Team,

I newbie to K6, for my scenario. I’m getting an HTML response, from there I need to capture a value and convert into pure text and pass it through form data. Any special functions or libraries are available to handle.


Hello Gerard, and welcome to the forum!

Have a look at findBetween. There are alternative ways of extracting values to responses depending on what kind of content you’re dealing with. E.g. if you have a JSON response, you may find it easier to interact with it using selectors instead.

Hi @Tom,

In my scenario, I was able to extract the value from the response. The only thing I need to convert the HTML to text, therefore from

JMeter I used ${__unescapeHtml(${correlationname})} or from the

LR we use function like web_convert_param(“correlationname”,“SourceEncoding=HTML”,“TargetEncoding=PLAIN”, LAST );

Gatling we use the Gatling EL like “#{foo.htmlUnescape()}”

Any similar implementation on K6.

Can you share an example of the string you need to unescape? Most encoded strings can be handled with decodeURIComponent but there are some types of encoding that need a different approach.


from the response i’m getting a string like this

Where I need to cover this to like this

Hi @Gerard can you provide the script that produced this string as this might a bug?

@Tom & @mstoykov
from the response, the quotation symbol convert into to HTML (HTML escape characters)

What I need, to cover the above response to like below and send it to a form data.

@Gerard looking at the example you have given, there really is another " at the end (and probably more) so the function does what is expected :). And I would expect any other function unescapping HTML to do the same otherwise I would consider that a bug.

IMO there is a good chance what you get in the end is what you get with all other tools and you just haven’t noticed and the next steps where you use it, will just work with the value you think is … wrong.

A hackish way would be to simply replace " with " if that’s the only encoded character in the string:

export default function () {
  const test = 'string"with"quotes';

  let result = test.replace(/"/g, '"');
1 Like

@Tom & @mstoykov

The solution tom provided solved the current problem. But there are several HTML escape characters and several encoding and decoding situations there while doing performance scripting. We can update the above snippet accordingly on some level. It’s better to have a dedicated feature or function to handle this type of encoding and decoding.

Most of the time when we start scripting encoding and decoding are now heavily used on the script.

Thanks Guys :+1: