Skip to content

parseOrigin in undici throws "InvalidArgumentError" for URLs with paths #3999

Open
@ahmed-oues

Description

Bug Description

The parseOrigin function in the undici library throws an InvalidArgumentError when a URL contains a path, query, or fragment. This behavior makes it difficult to use the library with valid URLs like https://api.domain.com/elastic/. that's because of an if condition in the function.

This strict validation seems unnecessary for some use cases, and there should be a way to relax it.

Reproducible By

Modify parseOrigin to allow URLs with paths.
Alternatively, provide an option to bypass this validation.

navigate to \node_modules\undici\lib\core\util.js
`function parseOrigin (url) {
url = parseURL(url)

if (url.pathname !== '/' || url.search || url.hash) {
throw new InvalidArgumentError('invalid url')
}

return url
}will be function parseOrigin (url) {
url = parseURL(url)

if (url.search || url.hash) {
throw new InvalidArgumentError('invalid url')
}

return url
}`
or sothisng selse semeler to that just without the exception of a "/"

Expected Behavior

Logs & Screenshots

Node.js version: v18.20.4
Undici version: X.X.X

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions