Skip to content

v7.x undocumented backward incompatibility of url.format() #11103

Closed
@mrtbld

Description

@mrtbld
  • Version: v7.5.0
  • Platform: Fedora release 23 (Twenty Three) Linux 4.8.13-100.fc23.x86_64
  • Subsystem: url

Latest major release v7.x changes the default value for slashes in url.format() when given objet has a hostname but no protocol. Previously slashes: true wasn't needed in that case, but now it is.

Example:

$ node --version
v6.9.5
$ node
> url = require('url')
> url.format({ hostname: 'foo.example', pathname: '/bar' })
'//foo.example/bar'
$ node --version
v7.5.0
$ node
> url = require('url')
> url.format({ hostname: 'foo.example', pathname: '/bar' })
'foo.example/bar'
> url.format({ hostname: 'foo.example', pathname: '/bar', slashes: true })
'//foo.example/bar'

Generating scheme-relative URLs is useful for a website that support both http and https; this is a common use case IMHO.

I found no mentions of this in the changelog. I believe it's a side effect of commit 336b027 regarding file: URLs (removal of !protocol condition).

Is this a bug or just a changelog oversight? API documentation seems to be in line with this new behavior (since v6.x), is this an undocumented bugfix then?

Metadata

Metadata

Assignees

No one assigned

    Labels

    urlIssues and PRs related to the legacy built-in url module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions