-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Env var not evaluated correctly in pre-request for v18 v19 v20 #2557
Comments
The behavior of the request object (URLs, headers, body) being interpolated before the pre-request execution has caused several issues. For example, consider the following scenario: The request URL is: And the pre-request script contains: bru.setVar("token", "secret token"); In this case, if interpolation happens before the pre-request script is executed, the code in the script becomes ineffective, as the URL would already have been interpolated without the updated token value. That said, I agree that there should be a way to enable request object interpolation ahead of time when needed. I’m considering introducing a |
I find this to be an annoying limitation on an otherwise fantastic piece of software. The above example seems contrived to me: why would you use a var in that case? I believe there are some cleaner options which don't require any assumptions about variable interpolation not having been performed yet. So in order to make this contrived example work, Bruno is breaking my (IMO perfectly normal) use case for which I need interpolation to have been performed before my script is run:
As a workaround, I've implemented this function which returns the interpolated URL (using environment variables only, which is what I need, but I guess Bruno also allows other types of variables in the URL, so this function could be improved): function getInterpolatedUrl() {
const url = req.getUrl();
const variableRegex = /\{\{([^\}]+)\}\}/g;
return url.matchAll(variableRegex).reduce((transformedUrl, match) => transformedUrl.replaceAll("{{" + match[1] + "}}", bru.getEnvVar(match[1])), url);
} |
I have checked the following:
Describe the bug
Since v18, the environment variable is not getting evaluated correctly in pre-request. As you can see in my screenshots, in v17, the env var gets evaluated with the correct value while v20 does not get evaluated at all and stays with the double brackets {{}}. I'm also attaching my simple test file/collection.
.bru file to reproduce the bug
Test collection to reproduce the above bug reported.
bruno-test.zip
Screenshots/Live demo link
The text was updated successfully, but these errors were encountered: