Skip to content
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

feat: add mac address validation #270

Merged

Conversation

ariskemper
Copy link
Contributor

No description provided.

Copy link

netlify bot commented Nov 27, 2023

Deploy Preview for valibot canceled.

Name Link
🔨 Latest commit 68802fe
🔍 Latest deploy log https://app.netlify.com/sites/valibot/deploys/65720a342a68bf000924fbda

@fabian-hiller fabian-hiller self-assigned this Nov 27, 2023
@fabian-hiller fabian-hiller added the enhancement New feature or request label Nov 27, 2023
@fabian-hiller
Copy link
Owner

Thank you for creating this PR! I plan to include this in our next release.

@ariskemper
Copy link
Contributor Author

@fabian-hiller thanks, valibot looks like nice lightweight validation library. Looking forward to contribute more to the project.

@fabian-hiller
Copy link
Owner

Thank you so much! Your words mean a lot to me. I plan to reach v1 beta in January. In about 3 weeks I will be able to work full time on my open source projects again.

@fabian-hiller
Copy link
Owner

Your implementation looks good. I'm just not sure what a valid MAC address is. Do all MAC addresses have to be 12 hexadecimal numbers long? Who defines this standard? Is there a clear source?

The following formats are clear:

  • 00:00:00:00:00:00
  • 00-00-00-00-00-00
  • 0000.0000.0000

But I am still unsure about the following formats:

  • 0000:0000:0000:0000 // Colons instead of dots and 16 digits
  • 00:00:00:00:00:00:00:00 // 16 instead of 12 digits

@fabian-hiller
Copy link
Owner

Also I am unsure if we should rename the function to macAddress. Do you have an opinion on this?

@ariskemper
Copy link
Contributor Author

ariskemper commented Nov 28, 2023

There are 48 bit (IP4 style ) and 64 bit (IPv6 style ) MAC addresses. MAC addresses are formed according to the principles of two numbering spaces based on extended unique identifiers (EUIs) managed by the Institute of Electrical and Electronics Engineers (IEEE): EUI-48—which replaces the obsolete term MAC-48—and EUI-64.

Regarding naming, i was allready thinking to name it macAddress, but since you have naming ipv4 and ipv6 instead ipV4Address i name it just mac, but i think macAddress, could be more meaningfull.

Maybe we should split to 2 validators: mac48Address and mac64Address

Your implementation looks good. I'm just not sure what a valid MAC address is. Do all MAC addresses have to be 12 hexadecimal numbers long? Who defines this standard? Is there a clear source?

The following formats are clear:

  • 00:00:00:00:00:00
  • 00-00-00-00-00-00
  • 0000.0000.0000

But I am still unsure about the following formats:

  • 0000:0000:0000:0000 // Colons instead of dots and 16 digits
  • 00:00:00:00:00:00:00:00 // 16 instead of 12 digits

@fabian-hiller
Copy link
Owner

I think both mac and macAddress are appropriate names. We can start with mac and rename it later if necessary. Are you sure the regex complies the standard? Then I would rely on you. I have not found a source on the Internet that describes the standard in a concise way. This document probably contains everything but I don't have the time to read it in detail right now.

@ariskemper
Copy link
Contributor Author

@fabian-hiller i believe current implementation should be ok, maybe we should just split to different validations, how it is done for ip, ipv4, ipv6 or leave it as it is for now.

@fabian-hiller
Copy link
Owner

How would you divide it and also name it?

@fabian-hiller
Copy link
Owner

Should we split it into mac48 and mac64, similar to IP validation, and also offer mac if both are accepted?

@ariskemper
Copy link
Contributor Author

@fabian-hiller i believe this would be a good idea, since mac64 supports newer 64 bit identifiers, which were added for IoT purpose. Will add this in the next days, so it could be merged in next release.

@fabian-hiller
Copy link
Owner

Thank you for your contribution! I will review and merge this PR soon.

@fabian-hiller
Copy link
Owner

I'll merge this PR. Can you still confirm again that the following formats are valid?

MAC 48:

  • 00:00:00:00:00:00
  • 00-00-00-00-00-00
  • 0000.0000.0000

MAC 64:

  • 00:00:00:00:00:00:00:00
  • 00-00-00-00-00-00-00-00
  • 0000.0000.0000.0000
  • 0000:0000:0000:0000

@fabian-hiller fabian-hiller merged commit 0cf3b33 into fabian-hiller:main Dec 7, 2023
10 checks passed
@ariskemper
Copy link
Contributor Author

@fabian-hiller per my research this are valid formats for 48 and 64 bit MAC address.

@fabian-hiller
Copy link
Owner

v0.23.0 is now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants