fwup icon indicating copy to clipboard operation
fwup copied to clipboard

Remove escaping of backslashes to support literal ${var}

Open fhunleth opened this issue 1 year ago • 0 comments

THIS IS A BACKWARDS INCOMPATIBLE CHANGE. THE PR IS IN DRAFT MODE TO SEE IF IT ACTUALLY AFFECTS REAL USE CASES AND TO THINK ABOUT MAKING IT OPT IN.

Automatic escaping of backslashes made it impossible to write ${var} to a U-Boot variable. When doing this, you have to remember that fwup evaluates variable substitution twice - once when making the .fw file and once when applying it. You obviously have to escape the $ when creating the .fw file. That made sense. Then to survive the apply step, you'd think that you could double escape the $. You'd be wrong, though, since fwup was escaping the backslashes that you were adding. Therefore, the variable substitution was guaranteed to happen since you couldn't double escape a $.

Amazingly, this behavior was never tested in the regression tests. When you run into it, it's weird enough to be pretty confusing, imho. Hopefully that and how rare should have been in real uses cases makes this something that no one actually did.

This changes string processing to not automatically escape backslashes so that it is possible to escape a $ through to the end. This allows you to write a U-Boot environment variable with a ${var} in it. This locks down string processing behaviors by adding unit tests.

fhunleth avatar Jan 29 '24 04:01 fhunleth