Giter VIP home page Giter VIP logo

Comments (12)

kanongil avatar kanongil commented on May 28, 2024

Note that this issue also effects optional params, which are omitted from the output when empty, contrary to what the docs say.

from call.

kanongil avatar kanongil commented on May 28, 2024

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:

if (value) {

from call.

kanongil avatar kanongil commented on May 28, 2024

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.

kanongil avatar kanongil commented on May 28, 2024

@hueniverse ping?

from call.

kanongil avatar kanongil commented on May 28, 2024

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.

hueniverse avatar hueniverse commented on May 28, 2024

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.

kanongil avatar kanongil commented on May 28, 2024

@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.

hueniverse avatar hueniverse commented on May 28, 2024

So either you get the number of path parameters in the config or null in the array?

from call.

kanongil avatar kanongil commented on May 28, 2024

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.

hueniverse avatar hueniverse commented on May 28, 2024

How do you handle a path like /{p1}/a{p2?}b/{p3?}? Even when p2 is null, you still have 3 segments.

from call.

kanongil avatar kanongil commented on May 28, 2024

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.

lock avatar lock commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.