Comments (4)
It would likely be useful for the API to provide some reasonable means of handling validity state.
I think we need to start with flushing this out more. See also 1 of https://whatwg.org/faq#adding-new-features.
from url.
With regards to adding properties on the URL value: what happens if you mutate the value using one of the property setters?
For instance, let's imagine the path contains a % sign which is not part of a percent-encoded byte (e.g. https://example.org/%s
). This would produce an invalid-url-unit validation error, and url.valid
(option A) of the resulting value should return false.
Now let's imagine somebody uses the path setter to change the path to something valid. Does url.valid
still return false?
In general, how do we know there is not some other component which also contains non-valid contents (e.g. the same %s
in the query)?
from url.
For options A
and B
, the new properties would reflect the current state of the sum of the URL
components, so if modifying a setter value changes the validity of the URL, the property would be changed to reflect that.
from url.
It would also reflect the last operation, wouldn't it? For instance, non-fatal validation errors can occur when an IPv4 address contains non-decimal parts - e.g. https://0x7F.1
. What's interesting about this is that the parser reformats the IP address so that it is valid - the above produces the URL https://127.0.0.1
.
In other words, this property would not be idempotent.
const url = new URL('https://0x7F.1');
console.log(url.valid); // false
const url2 = new URL(url.href)
console.log(url2.valid); // true!
I think this would be extremely difficult for users to understand or use effectively.
This suggests that validity may not in fact be a property of the URL, but rather a property of the inputs used to create the URL. So C (including "strict" versions of property setters, etc) would be the best API, IMO.
from url.
Related Issues (20)
- "valid host string" does not allow for percent-encoding
- "valid domain" does not match validation errors in the host parser
- IdnaTestV2.json "xn--xn--a--gua.pt" test case problem HOT 4
- A '@' character in the host part of file URLs HOT 2
- An opaque-host parser and percent encoding HOT 2
- Use in HTTP2/3 Pseudo-Headers HOT 5
- URL path shortening for ../ creates problem with other URL parsers that do not follow the whatwg standard HOT 6
- URL path comparison
- Web compatibility issue with various unknown (external) protocols like ed2k HOT 10
- Clearly mark conformance checking-only aspects of the IDNA section
- Explain why valid domain needs to run ToUnicode HOT 3
- Hoist "forbidden domain code point" check into "domain to ASCII" HOT 4
- Encourage denoting character-attributable errors by the REPLACEMENT CHARACTER
- CheckHyphens isn't set to beStrict
- Initialize the IgnoreInvalidPunycode flag when calling UTS 46 HOT 3
- Inconsistency in Handling `special-scheme-missing-following-solidus` URLs HOT 5
- Punycode behavior for labels exceeding DNS length is ill-defined HOT 8
- deprecated `punycode` HOT 1
- Proposal: URL.setSearchParams() HOT 3
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 url.