normalize single hex digit fields to two hex digits #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The "canonical" and "windows" format for MAC addresses with six hex fields separated by colon or dash allow single digit fields (the corresponding regular expressions explicitly use
{1,2}
to allow single or double digits), but these are converted incorrectly to packet octets.For example, inputs
01-2-03-04-05-06
and01-2-3-04-05-06
should both act like01-02-03-04-05-06
, but the first acts like01-20-30-40-50-06
(shifted nibbles), the second like01-23-04-05-06
(too short). Neither of these is even remotely likely to be what the user intended. On the other hand,01-02-03-04-05-6
does act like01-02-03-04-05-06
.To fix this, one could either (a) be less lenient with user input and reject input with single digit fields as invalid, or (b) ensure correct interpretation of such input.
Considering it the safer and more user-friendly choice, I followed option (b) by adding an intermediate step to insert leading zeros where appropriate. Admittedly, this breaks installations where a user purposefully uses
01-2-03-04-05-06
to stand for01-20-30-40-50-06
, or uses01-2-3-04-05-06
to purposefully send a completely invalid WOL packet. I consider this highly unlikely.If there is a normative specification of these two formats that explicitly forbids such single digit edge cases, it would be cleaner to follow option (a) instead (i.e., replace
{1,2}
with{1}
in the respective regexes). However, I am unaware of any such specification. As an example, RFC7042 uses leading zeros, but describes that convention merely as "notation used in this document".