Fix newline handling in BYTES directive#225
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #225 +/- ##
=======================================
Coverage 86.78% 86.78%
=======================================
Files 19 19
Lines 1052 1052
Branches 114 114
=======================================
Hits 913 913
Misses 104 104
Partials 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| ("BYTES(\xaa\x55\x00\x02\x08\x01\xf4)", b"\xaa\x55\x00\x02\x08\x01\xf4"), | ||
| # "\x0a" == "\n" | ||
| ( | ||
| "BYTES(\xaa\x55\x00\x03\x08\x0a\xb0\x3a)", |
There was a problem hiding this comment.
Could one directly use \n ?
There was a problem hiding this comment.
Yes, it works when replacing \x0a with \n in the test case. I just committed that new test case. However, since to_bytes is evaluated on internal python objects after the yaml is parsed and loaded (at least by my understanding), the yaml loader could potentially mangle \n escapes as it reads the file. To be absolutely sure, passing in a yaml device definition file as part of the test would be required. Is it worth doing that, or just "trust" the yaml loader to not have unexpected behavior?
The directive parser would not match any BYTES directive with a newline character in it due to regex dot pattern not matching newline by default.
for more information, see https://pre-commit.ci
Fixes the BYTES directive introduced in #220 not handling newline characters properly.