-
Notifications
You must be signed in to change notification settings - Fork 11
Handling empty tokens or "//" when generating URLs #35
Comments
in ease of use, i agree. it might hide mistakes in some situations by still producing a valid url that is unexpected, but i think thats a trade off we can live with here. for the third idea, we could use a question-mark syntax similar to regular expressions, something like |
Maybe an option: url_schema: /{url_part}/{title}
collapse_slashes: true |
Would "slash" be the right word? |
@wouterj wdyt? |
+1 for a collapse_slashes (i think that name is understandable) and defaulting that to true. |
I would rather default to false, as defaulting to true could cause content to appear in unexpected places without warning (e.g. |
or maybe we should even allow filters to be applied to the entire string: uri_schema: /{foo}/{bar}
token_providers:
- ...
filters: [ "slugify", "collapse_slashes" ] |
the filters is an interesting idea as well!
|
I'm -1 on filters. It would bring yet another concept to the RoutingAuto and I'm not sure of if there are more use cases than stripping repeated slashes. I'm leaning towards @dbu's suggestion: Btw, this also makes me wonder if we should add an option to say that a token can be optional or should be required. In the latter case, if the token provider returned null for such a token it would throw an exception. |
Re. the inline solution: After having a look at that Symfony PR I'm not sure how it addresses our problem here - the syntax is about matching routes, here we are talking about modifying the path when creating a route. i.e. What we are effectively saying with the The The array approach Another method: we could add a global option to the token providers: uri_schema: /{token_1}/{token_2}
token_providers:
token_1: [ 'content_foo', { remove_trailing_slash_on_empty: true }]
token_2: .. Thats quite verbose, but this is not something that needs to be done often, and the options resolver provides little room for people to get confused. |
Re. the required tokens, I think that makes sense. We could default to throwing an exception on empty tokens (and so avoid the |
i think the allow_empty makes a lot of sense. and removing a trailing slash if the token is empty would be the right thing to do (no need for even a config option imo) as long as /{token_1}{token_2}/{token_3} still works? not every token must be enclosed in |
Fixed in #39 |
If you have a URL schema as follows:
Where
url-part
is a URL part stored in the Document, e.g.store/product
.It is possible that the
url-part
is empty, in which case the URL "//" is generated. In this case it would be required to collapse to a single "/".We can fix this in a number of ways:
[ "{url}", "{title}" ]
and the generator will implode on "/" after removing empty values.I think the first option is the most viable., but it does mean that the user would be responsible for ensuring that the
url-part
(in the above example) is not empty in order to ensure not breaking the path scheme they have created.The text was updated successfully, but these errors were encountered: