-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Bug]: Environmental variables: Unable to prevent escaping #1919
Comments
For anyone that needs a solution right now, since I failed to rectify it via Coolify environmental variables, I pre-processed the variable directly in code like so: function unescapeJsonString(possiblyEscapedJsonString) {
let correctedString = possiblyEscapedJsonString;
// Check and conditionally remove leading and trailing single quotes
if (correctedString.startsWith("'") && correctedString.endsWith("'")) {
correctedString = correctedString.slice(1, -1);
}
// Replace escaped double quotes with actual double quotes only if needed
if (correctedString.includes('\\"')) {
correctedString = correctedString.replace(/\\"/g, '"');
}
// Replace escaped newlines with actual newline characters only if needed
if (correctedString.includes("\\\\n")) {
correctedString = correctedString.replace(/\\\\n/g, "\\n");
}
// Attempt to parse the corrected string into a JSON object
try {
return JSON.parse(correctedString);
} catch (error) {
throw new Error(`Error un-escaping JSON string: ${error}`);
}
} |
I have added a |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Description
Environmental variables containing a double quotation mark or a newline cannot be prevented from being escaped (wrapping it inside a single quotation mark does not work).
If I set the following environmental variable:
MY_JSON={"name": "John", "Address": "New York \n BigBen 173"}
It will get escaped, like this:
MY_JSON={\"name\": \"John\", \"Address\": \"New York \\n BigBen 173\"}
This is traditionally prevented by wrapping the value with a single quote ('), and it did work in last versions of Coolify. However, when I do that in the Developer View, it just removes the single quotes upon saving, and if I do it from the UI view of environmental variables, it keeps them there, but also escapes them, like so:
MY_JSON=\'{\"name\": \"John\", \"Address\": \"New York \\n BigBen 173\"}\'
This breaks e.g. apps that have a JSON inside theirs .env. If we were to parse this in code (e.g.
JSON.parse(process.env.MY_JSON)
, it throws an error.Minimal Reproduction (if possible, example repository)
MY_JSON={"name": "John", "Address": "New York \n BigBen 173"}
in any project (I tested it on a NextJS instance)MY_JSON={\"name\": \"John\", \"Address\": \"New York \\n BigBen 173\"}
Exception or Error
No response
Version
v4.0.0-beta.248
The text was updated successfully, but these errors were encountered: