0
votes

I need to correctly parse authenticity token in JMeter which has +, / and spaces in it and looks like below…

<meta content="authenticity_token" name="csrf-param" />
<meta content="kJ+AzaV/saCxK+F4Ibh6LeEqH8rpiGZfyRKn3RGX960=" name="csrf-token" />

I have a “Regular Expression Extractor” and Regular Expression looks like.. meta content="([^"]+)" name="csrf-token" />

The problem is that the / gets replaced with %2F and = at the end gets replace with %3D and

kJ+AzaV%2FsaCxK+F4Ibh6LeEqH8rpiGZfyRKn3RGX960%3D

How can I parse the authenticity token correctly?

2

2 Answers

0
votes

It looks like your attribute has been URI encoded, so you'll need to decode it before attempting to do more

window.decodeURIComponent('kJ+AzaV%2FsaCxK+F4Ibh6LeEqH8rpiGZfyRKn3RGX960%3D');
// "kJ+AzaV/saCxK+F4Ibh6LeEqH8rpiGZfyRKn3RGX960="

Further, using a RegExp to extract data from HTML or XML is not always the best idea, perhaps you could try parsing it and accessing the Nodes and Attributes you want via a DOM Tree.

0
votes

If you're passing it as a parameter just untick "Encode?" box for it.

If you need to decode this via JavaScript as Paul S. suggests, consider using __javaScript function as follows:

${__javaScript(decodeURIComponent("${YOUR_VARIABLE_NAME_HERE}"),)}

See How to Use JMeter Functions post series for more details.