Comments (12)
Note that this issue also effects optional params, which are omitted from the output when empty, contrary to what the docs say.
from call.
It seems this used to work but got broken with fc7978b.
The internal lookup still returns the correct values but unfortunately it no longer includes empty strings in the final output, due to the check here:
Line 123 in 260bb6c
from call.
So this issue has been there since hapijs/hapi#1644, which initially broke the directory
handler for paths containing dynamic segments.
At the time you seem to think that you fixed a bug, though it is not apparent which one. What is apparent is that the documentation still reflects the old behaviour, and that it broke some uses of the directory handler, where the implementation expects the length of the paramsArray
to equal the number of segments in the route in order to extract the value in the final segment.
For reference, this is the line in the docs that specifies the old behaviour:
For example, the route '/book/{id?}' matches '/book/' with the value of request.params.id set to an empty string ''.
While I wouldn't mind fixing this in inert
, it is not possible to do this without changing the api, and no longer use paramsArray
. As such, I would prefer if this is fixed in hapi/call, by always including every segment in the matched params. I have made an attempt at this here https://github.com/kanongil/call/tree/empty-segment-fix, which can be installed into hapi, passing all existing tests.
from call.
@hueniverse ping?
from call.
While your patch helps, I suspect your fix will still cause issues with Inert, without the undefined
entries from my fix. Let me get back to you on this.
from call.
Returning an object with keys explicitly set to undefined is a bad API. You can get the number of total params from the route info.
from call.
@hueniverse So this is definitely still an issue for inert when the slash is missing.
I wouldn't mind retrieving the total count from the route, however this is not exposed in the request.route
object. I can only retrieve the configured path
, or the fingerprint
. While I could parse this, it seems prone to errors and wasteful to do on each request.
Btw. I don't care about undefined
in the params
object. Only in the paramsArray
.
from call.
So either you get the number of path parameters in the config or null
in the array?
from call.
Yes, I will need one of those. If it's null
/ undefined
, the old expected behavior is restored. That solution has the bonus ability to also signal missing elements elsewhere in the path, though I won't need that (is it even possible?).
from call.
How do you handle a path like /{p1}/a{p2?}b/{p3?}
? Even when p2
is null, you still have 3 segments.
from call.
Hmm, I think relying on paramsArray
is not a good idea. I found another way to do this in hapijs/inert#79, which fixes my issue for any version of hapi.
from call.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
from call.
Related Issues (20)
- Update boom HOT 1
- Paths Matched Literally Have Different Params than Paths Matched with Mixed Nodes/Edges HOT 4
- Update hoek v6 HOT 1
- Remove engines HOT 1
- Route A: HOT 1
- Commercial version of v4 branch HOT 1
- Change module namespace HOT 1
- Update deps HOT 1
- Action required: Greenkeeper could not be activated 🚨 HOT 1
- Missing API file for V4
- Drop node 8
- Improve performance
- Special case '/'
- Only node 12
- Switch to use maps
- Switch tables to maps
- Check method exists
- Check method exists
- Link to Eran Hammer's comments on route conflicts is broken
- Parameters in path with `-` mark the path as invalid HOT 2
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 call.