URI.js: bug: cannot get domain of URI missing protocol

> URI('portquiz.net:8').domain()
< ""

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 1
  • Comments: 18 (6 by maintainers)

Most upvoted comments

In that case I’d prefer to go the functional programming route:

URI.withDefaults({ protocol: 'http' })('portquiz.net:8');

var httpUri = URI.withDefaults({ protocol: 'http' });
[ 'portquiz.net:8' ].map(httpUri);

This would allow the API user to do the work only once.

Now the next question (less question, more obstacle) is if the defaults transcend the URI.parse() method, so that the following behaves the same way:

var uri = URI.withDefaults({ protocol: 'http' })('portquiz.net:8');
uri.href('portquiz.net:9')

I guess URI.withDefaults() would work like a factory, bootstrapping the URI “class” so that any instance of that customized URI behaves consistently. We’ve dealt with this in an ugly and global way in the past, as URI.escapeQuerySpace can attest.