netlify-plugin-inline-functions-env
netlify-plugin-inline-functions-env copied to clipboard
Inliner double escapes special characters in env vars
My use case for the plugin is that I have a private key as an environment variable which requires new lines to be preserved.
Here's a shortened example of the env var, stored in Netlify:
------BEGIN PRIVATE KEY------\nabcsdflkshndfs\nksjdfksjdhfsd\n------END PRIVATE KEY------\n
The issue that arises when using the plugin is that all \n
characters are double escaped which results in the private key looking like this:
------BEGIN PRIVATE KEY------\\nabcsdflkshndfs\\nksjdfksjdhfsd\\n------END PRIVATE KEY------\\n
Notice that all \n
instances have been replaced with \\n
which breaks the private key.
My current workaround is to do this in the function file:
process.env.MY_PRIVATE_KEY.replace(/\\n/g, "\n"),
This isn't entirely ideal! I was looking through the source code for the plugin, attempting to locate the culprit of the double escaping behaviour, but I can only determine that it's probably a feature of babel, for example on line 14 of index.js:
babel.createConfigItem(...
Would it be possible to include a configurable option in the plugin to escape special characters when inlining? (Setting the default to true as not to introduce a breaking change?)
Thanks! Salma