-
Notifications
You must be signed in to change notification settings - Fork 22
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
Consider a string syntax instead of a dictionary #4
Comments
So, I started with a flat string representation, but moved to the dictionary for the follow reasons:
I expect to get more feedback at TPAC around all the issues you filed and will update more after that point. |
Wow. I did not realise legacy scope match allowed you to specify query parameters, and then mandated that they appear at the start of the URL in the exact order specified in the scope. That's ... pretty nasty. (And it isn't explicit in the spec, it's just implied by the fact that the scope is a URL prefix.) So it turns out the manifest scope algorithm doesn't match service worker, because in the manifest, we only match the origin and path. I don't see any merit in a query match that cares about the order of query parameters (it just seems like a way to let developers shoot themselves in the foot; e.g., using a hash table to generate query parameters resulting in a pseudo-random parameter ordering which sometimes matches and sometimes doesn't). Ideally, the new pattern would only let you match in any order, leaving the exact order matching as an unfortunate feature of the old match algorithm. Edit: And hence, for point 2, I think we could define a string syntax that always (explicitly) ignores the order that you specify in your pattern, and always allows parameters in any order. For point 3, we could add that to the string syntax also, e.g., in the future allowing |
Well, we have to support legacy web features whether we consider them useful or not. I don't think we can just remove it.
There are other extensions that would not be so easily supported in a single string. One that comes to mind: What if we wanted to add the option to "OR" search parameters together. If we devote normal search syntax to "AND" logic then it seems we'd have to create some crazy new syntax to reflect the other logical mode in a flat string. In comparison, a dictionary makes this easy by adding a Also, from an implementation point of view I think a dictionary approach would be much more manageable. We can keep individual pattern string syntax relatively simple which limits the risk of introducing security errors in the parser. It also makes it easier to define a small set of features today that can be extended in the future. |
Which legacy web feature are you referring to? The fact that SW I'm not suggesting we remove that from the old syntax, but that it isn't exposed in the new URLPattern syntax. You'll still be able to do The other points make sense. |
Yes
Currently we have a consistent internal representation of the pattern whether the user provided a legacy scope string or not. Its always represented internally as a pattern. That pattern is exposed as Making legacy and new pattern scopes support a disjoint set of things will complicate the implementation. It will also make it harder to create a consistent API like |
That's understandable, but I'm also not sure we should create a new feature that lets people do something we all agree is bad, just to simplify the implementation. The solution to the implementation could be that there's an internal member on that dict called "requireQueryFirst" or something, which is set to true when parsing a legacy scope, but cannot be set from user-space when defining a URLPattern (it's always false). If you go with this implementation, you need to find a way to squish all possible query strings into the key/value pattern data structure. Are you prepared to make the data structure that flexible just to accommodate legacy query prefix matching? You'd need to allow patterns for (starting each one with a specific example of a legacy
That seems like it has some edge cases that may not be supported by the current URLPattern proposal. I feel like it's simpler if you just create a separate implementation for legacy scope matching, at least for the query string part. You could, for example, have an option of either using the query matching dictionary, or treating the query as an opaque string and doing a prefix match (which would only be usable in the implementation for legacy scopes, not exposed in the public API). |
True. We could hide the legacy behavior in unexposed logic within URLPattern. It would basically be hiding the
I'm sorry, I got a little lost at this point. It seems to me that the original proposal can largely be implemented by parsing the URL to matched against using Anyway, I think the discussion of whether to hide the service worker prefix matching of search params from URLPattern is a different issue from the original topic here. |
In regards to string-vs-dictionary, I would be open to a convenience form that takes a string, but optionally also takes a dictionary to handle future extensions. My impression, though, is the manifest implementation would prefer not to have two possible types passed for a field. That is another reason I settled on the dictionary as it provides a single type for manifest and the extensibility I think we will need in the future. I don't think we'll be able to resolve this before the TPAC face-to-face, though. I'd really like to get a wider set of feedback around the tradeoffs. Also, if folks would prefer to remove URLPattern completely and do something service worker specific then it would be easier to do a simple string. Basically, I need agreement on use cases before we can really resolve this. |
Sorry, that was pretty confusing. I've edited my comment to show specific examples of each. The point is that because SW scope is currently a "dumb" prefix match, that actually implies quite a wide variety of different "modes" that a "smart" query matcher would need to emulate, and I'm not sure your current proposal captures all of those modes. Also, I'm not convinced that it's desirable to do so, since almost every single one of those (if not all) makes no sense. (There's no way to require a parameter I've also just made a proposal to deprecate query matching. Based on this discussion, I think it's so broken that it can't be used correctly, so we should just (attempt) to remove it, which would make things much easier both for this effort, and the unification of the manifest matching algorithm with this. (Again, I won't be at TPAC unfortunately, but I look forward to the outcome of these discussions.) |
My original proposal includes a "search The "search I think between these two modes we can meet all constraints. If we deprecate the legacy scope behavior we could hide or drop the |
Understood. I'll do my best to represent your position. Also, my impression is that @fallaciousreasoning from your team will be there. Is that correct? |
Yep! |
|
I summarized the TPAC discussion here: w3c/ServiceWorker#1468 (comment) I'm not sure the minutes call it out explicitly, but I asked many people for their opinion on string-vs-dictionary. The unanimous feedback I got was that we should use a dictionary and that a flat string was probably not practical. I was a little concerned about header representations of the dictionary, but I'm told there is an effort to support this with "structured headers". People did not seem concerned. Based on that consensus I'm going to mark this issue WONTFIX for now. Sorry! |
I wonder if a syntax for URL patterns would be easier to learn and read instead of designing a dictionary which takes up multiple lines just to express a simple pattern.
I'm thinking that it should basically have a syntax that looks like a URL with
?
and*
being special, and\?
(an escaped question mark) separating the path from the query, and with special treatment being applied to the query, allowing a match in any order.For example:
https://example.com/foo/bar/?*\?wiz=wham&zot=*
Means to match any URL starting with
"https://example.com/foo/bar"
or a sub-path thereof, AND which must have the"wiz=wham"
anywhere in its query param list, AND it must have azot
parameter with any value.wiz
andzot
can appear in any order, and the URL is allowed to have other query params, and they can come before or afterwiz
andzot
.The counter I can think of to this is that there's potential confusion to the user in that it looks like a glob or regex that would require those query parameters to appear in that order and first in the param list, where in fact we are creating a new type of URL-specific glob that treats query parameters separately (allowing them to appear in any order). Also having to write
/?
is ugly and you might forget the slash and create an entirely different meaning.The advantage of this would be that you can use it in both Service Worker and Manifest (a JSON dictionary) with the exact same syntax, since you'd be defining a syntax for a "URL pattern" rather than a class
URLPattern
(requiring a separate explanation of how to express it in a JSON dictionary).The text was updated successfully, but these errors were encountered: