Skip to content

Support ? and / as valid characters in params #42

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Support ? and / as valid characters in params #42

wants to merge 1 commit into from

Conversation

matthewdunsdon
Copy link

@matthewdunsdon matthewdunsdon commented Feb 8, 2017

Introduce the encoding of resource params, so params can contain "?" and "/" and still match routes

Description

Given I have the following params (in json):

{
  "id": "random?chars",
  "name": "catchy/name"
}

When I create a web resource:

var web = nap.web()
web.resource('/load/{id}/with/{name}', callback)

and I build my URI:

var myUri = web.uri('/{load/{id}/with/{name}', { "id": "random?chars",  "name": "catchy/name" })

then the following should work:

// Using tape
expect.plan(2)

var myCallback(req) {
  expect.equal(req.params.id, 'random?chars' , 'my random chars went through')
  expect.equal(req.params.name, 'catchy/name', 'my catchy name went through')
}

var req = web.find(myUri)
req.fn(req)

Motivation and Context

This PR exists because my expectation was not met.

  1. I would like to use nap and trust that I can pass a "?" as a character in my params and still have the request match. The ? would cause the rest of the uri to be treated as a uri query and not part of the path.
  2. I would like to use nap and trust that I can pass a "#" as a character in my params and still have the request match. The / would not be encoded so would seen as part of the path and not match the resource.

How Was This Tested?

Tested with unit tests.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change follows the style of this project
  • I have added tests to cover my changes
  • All new and existing tests passed

@coveralls
Copy link

coveralls commented Feb 8, 2017

Coverage Status

Coverage increased (+0.05%) to 98.496% when pulling 3c330ea on matthewdunsdon:handle-params-to-be-url-encoded into 77a2f35 on websdk:master.

@mstade
Copy link
Member

mstade commented Feb 9, 2017

This is a solid PR, but my gut feel is that this should be handled by rhumb, not nap. The uri method should probably move to rhumb (it can be re-exposed in nap) and certainly the logic in find should happen in rhumb.

How much of a rush are we in here, can we look at moving this to rhumb or should we just merge this and move it to rhumb afterward?

@matthewdunsdon
Copy link
Author

I'll make the changes to rhumb and reference it here once it has been created,

@matthewdunsdon
Copy link
Author

Related PR: websdk/rhumb#18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants