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

Implement allowUnicode option (defaults to true) #160

Merged
merged 6 commits into from
Jan 18, 2018

Conversation

papandreou
Copy link
Contributor

@papandreou papandreou commented Jan 17, 2018

As discussed on #156

This might be rather naive as I haven't looked at the full grammar. Let me know if there's anything it should cover :)

Copy link
Owner

@skeggse skeggse left a comment

Choose a reason for hiding this comment

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

Hey, thanks!

It's now been a long time since I originally wrote this code, and it's become less and less familiar to me. I suspect we'll need to add checks to other places such as here, given that the outer loop isn't the only place we access code point data.

lib/index.js Outdated
if (typeof options.allowUnicode !== 'undefined') {
allowUnicode = Boolean(options.allowUnicode);
}

Copy link
Owner

Choose a reason for hiding this comment

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

Simpler: const allowUnicode = options.allowUnicode === undefined || !!options.allowUnicode;

lib/index.js Outdated
token = String.fromCodePoint(email.codePointAt(i));
const codePoint = email.codePointAt(i);
if (!allowUnicode && codePoint > 0x7f) {
return false;
Copy link
Owner

Choose a reason for hiding this comment

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

This ignores the errorLevel option - at the very least, it should output an appropriate code when diagnose is true.

This demonstrates the imperfections of the errorLevel system as implemented, because the user might set allowUnicode to true, but set the errorLevel higher than the error code corresponding to disallowed unicode.

I guess we could also just note that this is the behavior for allowUnicode, and that errorLevel isn't really compatible with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to map it to an errorLevel value here: c3430a0

Let me know what you think.

@papandreou
Copy link
Contributor Author

@skeggse, thanks for taking a look! I think I covered all your points now :)

@skeggse
Copy link
Owner

skeggse commented Jan 18, 2018

Thanks! I think the error code you selected is about right; what do you think about making that error level specified by allowUnicode or some other parameter? It might be something more like:

Isemail.validate('a@b', {
  // Allow unicode
  unicodeErrorLevel: 0
  // Disallow unicode
  errorLevel: 20,
  unicodeErrorLevel: 25
});

I'm not super attached to either, and the PR as-is could ship otherwise - just wanted some feedback on whether you think this would be a better approach.

@papandreou
Copy link
Contributor Author

@skeggse, hmm, I'm not sure I have an opinion about that. Trying hard to put myself in the shoes of someone using the library in that way where various degrees of invalidity on a linear scale is required. Personally I think I'd rather specify exactly what I want to allow with individual options, but due to the amount of error cases I also see why that doesn't scale here.

Alternatively I guess I'd pick or make a more opinionated library that seemed reasonable so that I wouldn't need to dive into the details :)

@papandreou
Copy link
Contributor Author

what do you think about making that error level specified by allowUnicode or some other parameter?

That would be fairly easy to do, I guess. For consistency with errorLevel:true|<number> we should probably build it into the option itself instead of introducing a separate one. Might make more sense to invert the option and call it disallowUnicode or asciiOnly. I don't think I'd intuitively grasp that allowUnicode: 55 actually means "disallow unicode and assign an error level of 55 if violated".

@skeggse
Copy link
Owner

skeggse commented Jan 18, 2018

I think we just take this as-is, and resolve the remaining issue in #162.

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.

None yet

2 participants