-
Notifications
You must be signed in to change notification settings - Fork 114
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
dotenv octal escape unexpected behavior #650
Comments
I'm not confident with regex and the way those are used in this context, so hardly can tell what would be the adequate expression |
I've never used Go before looking at this. I just was bored and looked at the differences of various dotenv implementations and tried to replicate them in Rust, just for fun. I noticed these odd behaviors when my solution didn't produce the same results in some cases (I now emulate the behavior 1:1). I wrote down everything I noticed here: https://github.com/panzi/punktum#composego-dialect I also mention bugs in the variable substitution there, but didn't describe it well enough and now I can't remember the details. I think there's a problem in multi-line strings when the default value part spans multiple lines. Also I just noticed yet another bug. If the inheritance syntax is used in the last line of a FOO Is equivalent to this JSON: { "": "FOO" } Anyway, I wouldn't use regular expressions at all in implementing this, and neither would I use a library function for the escape sequences. Also I wouldn't do anything like escape sequence handling or variable substitution in separate passes. I find it simpler to think of when it is done in one pass. Because then the output of one pass doesn't need to prepare the string so that is correctly handled in the next (see So because I never used Go before, am not a fan of what I've seen of Go, and am very opinionated on how such a parser should be written, I'm probably not the right person to contribute code here. XD |
@panzi I ran into that too. It should be a separate issue. |
The regular expression for octal escape sequences matches too much (
0\d{0,3}
instead of0[0-7]{0,3}
, although that is still too much), replaces a\0
prefix with just\
, and then if the unquoting of the escape sequence fails it inserts the manipulated match.Meaning this value:
"\079"
Gives this string:
"\\79"
While it should give:
"\x079"
(bytes:[ 0x07, 0x39 ]
)I.e. this are two bugs. Using the manipulated match when unquoting fails and matching too much and thus failing valid octal escape sequences.
Edit: Also through trail and error I found out that
strconv.UnquoteChar()
wants octal escape sequences to be exactly 3 octal numbers long, meaning the regular expression should actually be0[0-7]{3}
, or the match needs to be0
-padded to 3 characters long.Further the regular expression also matches
\c
, which I can't find in the Go spec.compose-go/dotenv/parser.go
Line 19 in 9d0d133
compose-go/dotenv/parser.go
Line 225 in 9d0d133
The text was updated successfully, but these errors were encountered: