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 support for fully qualified domains (trailing dot in domain name) #96

Merged

Conversation

remusao
Copy link
Collaborator

@remusao remusao commented Jul 18, 2017

This should fix #95

I added a few tests, although I'm not sure they are all necessary since hostname cleaning happens before each of them. Although it still adds some value as documentation for valid use cases.

Also, during cleaning, I created two helpers:

  • one to strip spaces at the beginning of the string (does not seem necessary to do it at the end since URL.parse does it already).
  • a second one to strip trailing dots.

Let me know if it's good for you!
Rémi

@@ -17,16 +17,20 @@ var URL = require('url');
var hasPrefixRE = /^(([a-z][a-z0-9+.-]*)?:)?\/\//;
var invalidHostnameChars = /[^A-Za-z0-9.-]/;

function trim(value) {
return String(value).replace(/(^\s+|\s+$)/g, '');
function ltrim(value) {
Copy link
Owner

Choose a reason for hiding this comment

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

Thinking about it, we could also just use the plain old String.prototype.trim as it is supported since ECMAScript 5.0.

I'll make the change prior to publish the new release 👍

@thom4parisot thom4parisot merged commit 64bcd63 into thom4parisot:master Jul 18, 2017
@remusao remusao deleted the support-fully-qualified-domains branch January 10, 2019 20:00
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.

Invalid behavior for domains ending with a dot '.' (fully qualified domain names)
2 participants