Skip to content

is url.format broken or am I? #1176

@beck

Description

@beck

Using Node@9.9 on OSX.

Problem

> const url = require('url')
> url.format({hostname: 'dougbeck.me', pathname: 'womp.html'})
'dougbeck.mewomp.html'
> 😭

Am I crazy for thinking this is broken behavior?

Granted, this seems to be terrible in every other language:

Python

>>> urllib.parse.urlunparse(('', 'dougbeck.me', 'womp.html', '', '', ''))
'//dougbeck.me/womp.html'

Requiring a 6-item tuple is gross.

Ruby

> URI::HTTP.build(host: 'dougbeck.me', path: 'womp.html').to_s
ERROR expected absolute path

Java

> new URL("dougbeck.me").toString()
ERROR: no protocol

Node's behavior is worse than all of ☝️because it does not throw an error and returns a result that defies all intuition. 😖

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions