Some characters are transformed in environment variables


I am trying to store a regex with a named group as an env var in my worker and here is what it looks like in the wrangler.toml:

vars = {DOC_URL_PATTERN = ".+/docs/(?<project>[a-z]+)/.*"}

It works when I dev using wrangler dev but once I want to preview or deploy it fails because the env var is returned as .+/docs/(?2project4[a-z]+)/.*

The < is converted to a 2 and the > is converted to a 4…

Any idea how to deal with that?

Just guessing due to the URL pattern, could it be related to a URL normalization settings?

I don’t know, at this stage it’s just an env var with a string in it, it has no knowledge of what I want to use it for and should not try to transform anything.

How about using different regex approach?

(?<=<) for < symbol
(?=>) for > symbol

Or maybe \ before to catch it …

Have to try out, will write back … just to make sure, you need ...<project>... or just ...project... within the final result?

Regarding wrangler, I am not sure if it has to be passed as encoded or decoded for < >?

I need exactly .+/docs/(?<project>[a-z]+)/.* do be stored in the env var and I need it to be injected in the JS exactly like that without modification. The question is why env vars values are transformed by CloudFlare? (And not when using wrangler dev).