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

Add use of hyphen or spaces in MACaddress #1065

Merged
merged 2 commits into from
Jul 24, 2019

Conversation

ezkemboi
Copy link
Member

  • Allow use of hyphen and spaces has a valid MACAddress.

Ref: #1061.

Copy link
Member Author

@ezkemboi ezkemboi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments on my own work for discussion and also help guide fast reviews.

Cc. @profnandaa @chriso.

@@ -2,11 +2,13 @@ import assertString from './util/assertString';

const macAddress = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/;
const macAddressNoColons = /^([0-9a-fA-F]){12}$/;
const macAddressUsingHyphen = /^([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])$/;
const macAddressUsingSpaces = /^([0-9a-fA-F][0-9a-fA-F]\s){5}([0-9a-fA-F][0-9a-fA-F])$/;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a review of this work, but I tried doing:

/^([0-9a-fA-F][0-9a-fA-F](:|-)){5}([0-9a-fA-F][0-9a-fA-F])$/;

This is to allow use of - or : has proposed in one regex. The issue is that, it made this valid:
01-02-03:04-05-ab, which is not.
Separating the regex allowed to validate different options. It is a convention to use either :, - or .
On that note, I also added spaces, which was not in the initial proposed bug. But, on research, it is still a valid MACAddress.

If there is a better way of making the regex one instead of 3 or 4 variables, I am welcoming ideas from the community. Thank you.

Cc. @profnandaa @chriso

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see, the code looks okay, making it one regex will almost be the same logic since we will be OR'ing |).

Just a small nitpick, perhaps calling the variables ...With... instead of ..Using... will sound more "palatable" :)

Other than that, all LGTM 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, making the changes and pushing them.

@@ -2,11 +2,13 @@ import assertString from './util/assertString';

const macAddress = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/;
const macAddressNoColons = /^([0-9a-fA-F]){12}$/;
const macAddressUsingHyphen = /^([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])$/;
const macAddressUsingSpaces = /^([0-9a-fA-F][0-9a-fA-F]\s){5}([0-9a-fA-F][0-9a-fA-F])$/;

export default function isMACAddress(str, options) {
assertString(str);
if (options && options.no_colons) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also still figuring out, why do we need an option for colons?
Instead of just allowing different cases of validations.

Cc. @profnandaa @chriso

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that might not be necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure that I don't break on things, I will leave it for now.
And propose changes.
Thanks, @profnandaa.

Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped in my comments as reply.

@ezkemboi
Copy link
Member Author

Check on comments and replied to them.
Working on them.
Thanks, @profnandaa.

@profnandaa
Copy link
Member

@ezrqnkemboi - can you rebuild?

@ezkemboi
Copy link
Member Author

Alright, working on that.

Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the PR! 🎉

@profnandaa profnandaa merged commit 02896f3 into validatorjs:master Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants