Skip to content

withProtocol stips host when input is in {host}:{post} format #237

@sandros94

Description

@sandros94

Environment

Node.js 20 and Bun 1.1

packages:

  • Nuxt: 3.11.2
  • ufo: 1.5.3

Reproduction

I'm sufficiently secure this is more than enough

import { withHttp, withHttps, withProtocol } from 'ufo'

export default eventHandler(async (event) => {
  const host = 'localhost:9000'
  console.log(withHttp(host))
  console.log(withHttps(host))
  console.log(withProtocol(host, 'ftp://'))
})

Describe the bug

The reproduction outputs:

http://9000
https://9000
ftp://9000

Additional context

Discovered this while building a small app that will be containerized and deployed within a docker stack.

The host (picked from the runtimeConfig) is used to define the container hostname for the backend, and since they could bind or edit the default port I wanted to let them include into the env variable that overrides the runtimeConfig, but with my surprise that it also deletes the host part.

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions