-
Notifications
You must be signed in to change notification settings - Fork 37
Improvements to Router syntax #50
Comments
You can apply the change. Then we check if it brokes old codes, running all test cases. |
For sure it will break some test cases. I'm also experimenting now with another modification – optional parameter that could be passed to Action. TSingleStaticFileAction.register('/favicon.ico',False,'favicon.ico');
TSingleStaticFileAction.register('/',False,'main.html'); So I can reuse the same action for different resources. |
You can apply the changes separately. Thus, if there is error, it will be easier for us to fix. :) |
Test unit |
I'll fix the test cases now ... |
Done. Test case is OK now. I need to test your changes in router. The router code is the most critical part of the Brook. We have to be very careful when changing the logic there. |
You want to remove support to "*_/foo"? If yes, "_foo" will provide support for it? |
It is tricky part. If I can read the code correct, '/foo' is not supported now. It just equivalent to '' function TBrookRouter.MatchPattern
[...]
if VPt = AK + AK then
Exit; My implementation don't remove '/*_', but also don't support '/_path/foo' on itself. If we want to compare ending '/foo' and reject routes that don't have such suffix, we still need to implement it. |
And any change in router must be documented (with demos), like: https://github.com/silvioprog/brookframework/blob/master/core/brookaction.pas#L94. |
I forgot to comment...
But "/more/*/all" don't will create a variable. |
Yes. Your changes will be accepted, as long as the old examples (you can change examples too for use new feature) continue working. And that must be documented, for better comprehension that new feature provides. |
Seems a bug in new router code. See the test below:
Calling the URL In old router: 404 - Page not found (Correct!) |
The whole point of my modifications is for "_download" to _be* a variable. So your example with "/home/:var/*download/" behaves as I expected. There are some questions with trailing slash in my code, so I should check it. Possible suffixes could be something like Anything like "/home/*file/:var/" is not supposed to work because it is ambiguous. |
I'll test all your changes after you commit it. Please document all details and sample of it in And see other nice feature that will be implemented here: #52. We can implement it soon as possible. 👍 |
It will match patterns like too?:
Call: Result: If yes, it will be very nice! :) |
Yeah, with last commit it's possible with such syntax: TMyAction.Register('/home/:user/*path/download/:fileid'); Call Result will be { "user": "1", "path": "a/b", "fileid": "2"} I think old-style ...Working on documentation. |
I'll test all your changes now ... |
Before it is moved to the master branch we have a backup here: http://brookframework.org/backup/brookframework-20130818-1546.zip |
Some detected problems... The first is simple. For this test:
And this URL: The result is: So, should not be? There is no error, so if it is too difficult to change or use more processing, we can leave it as is. Now the second: In new implementation we can use only
In old router I wore it: |
Values in JSON dictionary is not sorted anyway, so there is no point in fixing first issue. One never should rely on order of keys in json. Second issue can be solved this way. You just specify: Honestly I can't imagine situation when you will need to match some part of url with /*/ and not use matched value. We can also hack the syntax to make /:/ = // (if variable name is not specified), but this would be confusing, because in all other cases * will match *any number of levels, not only one. |
The only utilizade of In old implementation I can:
and call:
or:
But, new implementation follows?:
:/ |
Ah, using regex I can solve it. E.g.: /home/:user/(my regex 1)/download/:fileid/(my regex 2) Regex doesn't creates variables. |
If new implementation allow |
It is ambiguous, how such pattern Now possible to use You just replace // → /:/ and /__/ → // to convert from old syntax to new. |
This way?:
|
So, if /*/ → //, then:
But, calling:
Returns 404. :/ |
If you want old-style Last ":" at the end will match only one level, of course. |
Hm... something weird or I really I don't understand. :/ Using this pattern:
I can:
or:
So, with:
Why |
It doesn't match because only first // is treated as a pattern. Second / is not a pattern in current implementation. It is just not obvious how to implement it, so I process only first one. Second is treated as literal "_", so this will match only I am aware of this limitation, and even documented it: "@bold(@italic(NOTE:)) Only one multi-level variable can be specified per URL." I think it will lead to confusion if something like How would you parse |
But you have plans to implement it, or we'll use only a single level?
I don't know too. :( How Backbone treats it? After we close this issue, I'll do a merge to master. |
Backbone is using RegExp behind the scenes. It is possible to use multiple '*splat' parameters in Backbone, but it is not documented. They use non-greedy pattern, so it will match minimal possible substring, just like I was not planning to support it because it is hard to implement. It will require too much efforts and testing for a feature almost no one will use. Maybe it will be easier to implement it using regexpr library, but regexps usually are much slower. Such a simple syntax and so many complications. Also I completely forgot about syntax like |
Sorry, but is not documented in Backbone or in Brook?
OK. No problems. We keep only the current implementation. This already meets the majority of cases. 👍
What does this do? This is already implemented in Brook? If yes, it needs to be document. |
... I forgot to say,
This is optional, so if the implementation for it decrease a little the performance, we can leave as already, because it can be validated in a constraint (I'll release the constraints soon). |
Multiple Syntax |
We can close this issue? :) If yes, I'll do a clean and then do a merge. |
Yes, let's close it. |
Currently action routing supports such syntax:
Single-part asterisk seems redundant to me, because you can always replace it with
/more/*/all → /more/:dummy/all and do not use value of dummy parameter.
Multi-part asterisk implementation is buggy, because it doesn't check suffix,
so /file/x-files/top-secret.pdf/denyaccess will also match /file//download** pattern. Besides being buggy, it is nearly useless, because action should parse whole URL to extract pathname of file. It would be great if the action somehow received x-files/top-secret.pdf as a parameter.
I propose slightly adjust router syntax:
(this is much like http://backbonetutorials.com/what-is-a-router/)
With such modification asterisk will match anything after
/file/
and place substring to parameter namedpath
. So Action could easily usepath
and open needed file.I could push some modifications right now, but we already have a lot of commits in working branch so I better hold down before current changes will be merged to master branch.
The text was updated successfully, but these errors were encountered: