Comments (2)
Hi. This is an annoying issue and edge-case indeed but the reason is that at least by spec, localhost:
can be a valid protocol and ufo cannot make a distinguish when input is in the form of host:port
alone and ufo utilities do not throw an error like new URL('localhost:3000')
does to require protocol.
One possible solution is that we make regex to be stricter and require ://
for host:port
pattern or add an exception list (*) of specific ones don't need it (such as mailto:
and tel:
) but it is tricky and we might consider a major version for it. thinking more.
(*) quick research for known exceptions: (as we see, this can extend)
['mailto:', 'tel:', 'urn:', 'data:', 'about:', 'javascript:', 'file:', 'blob:', 'magnet:', 'news:', 'sftp:', 'ssh:', 'feed:', 'webcal:', 'bitcoin:', 'geo:', 'sip:', 'sips:', 'sms:', 'smsto:', 'mms:', 'mmsto:', 'gtalk:']
extended list (thanks to chatgpt!)
['mailto:', 'tel:', 'urn:', 'data:', 'about:', 'javascript:', 'file:', 'blob:', 'magnet:', 'news:', 'sftp:', 'ssh:', 'feed:', 'webcal:', 'bitcoin:', 'geo:', 'sip:', 'sips:', 'sms:', 'smsto:', 'mms:', 'mmsto:', 'gtalk:', 'facetime:', 'chrome:', 'chrome-extension:', 'content:', 'dicom:', 'edis:', 'im:', 'info:', 'ldap:', 'mid:', 'gopher:', 'ni:', 'nih:', 'market:', 'moz:', 'ms-help:', 'ms-settings:', 'opera:', 'pres:', 'resource:', 'rmi:', 'rsync:', 'rtmp:', 'secondlife:', 'spotify:', 'svn:', 'tag:', 'vemmi:', 'view-source:', 'wais:', 'ws:', 'wss:', 'xfire:', 'xmlrpc.beep:', 'xmlrpc.beeps:', 'ymsgr:']
I would suggest that you change your application to either accept host
and port
separately or require that the single URL config always include a protocol itself in the meantime.
from ufo.
Sorry, I didn't notice I posted it on ofetch
, I must have mixed up the tabs (as I was double checking the docs to be sure I was using it correctly).
In reality I didn't notice this bug with localhost:
but with host.docker.internal:
(a local domain inserted by Docker Desktop to simplify the connection between services and application in dev). In production it will change to backend-container-name
(port 80 by default), or a domain if deployed separate.
from ufo.
Related Issues (20)
- fix: `normalizeURL` does not ensure path name starts with a `/` HOT 4
- Encoding query arrays with `name[]` convention HOT 7
- Only apply trailing slash utilities to supported protocols HOT 3
- Add a `withHash` function
- `searchParams` and `query` cannot be correctly mutated on $URL instance HOT 1
- Query parameter encoding - slash character does not get encoded HOT 3
- Add a without hash/fragment utility HOT 2
- Migrate to native `URL` HOT 2
- Utility to get url without host (path + query + [hash]) HOT 5
- withoutTrailingSlash incorrectly strips slash from last query parameter
- `joinRelativeURL` doesn't handle protocols
- Regex JOIN_SEGMENT_SPLIT_RE broke nuxt app HOT 5
- SyntaxError: Invalid regular expression: invalid group specifier name (Safari) HOT 1
- Additional utils: keepQuery and withoutQuery HOT 1
- Please encode " | " as %7C
- withQuery do not encode ';'
- protocol relative when using `withProtocol`
- Add `withPathParameters`
- Edge case where leading slash is removed in normal URL paths
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ufo.