-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parseOrigin in undici throws "InvalidArgumentError" for URLs with paths #3999
Comments
Thanks for reporting! Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that. |
Thank you for your response! Steps to ReproduceThe issue occurs when providing a connection URL to Elasticsearch that includes a path, such as
ExplanationThe error occurs because the Suggested FixI’ve created a pull request to address this issue: Relax ConclusionI believe this fix will resolve the issue while keeping the library flexible for real-world use cases. Let me know if further clarification is needed or if I can provide additional context. Thanks |
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
The text was updated successfully, but these errors were encountered: