Skip to content
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

Emails in path are not allowed by default #98

Closed
imrekoszo opened this issue Nov 22, 2015 · 2 comments
Closed

Emails in path are not allowed by default #98

imrekoszo opened this issue Nov 22, 2015 · 2 comments

Comments

@imrekoszo
Copy link

I came across a situation where I needed to create an api with a path like "/foo/by-email/aaa@example.com" where the email is a route param. It appears bidi does not let you do that currently without a regex specification of the email. Please see example below:

(deftest email-in-path-test
  (testing "fails without regex"
    (let [route [["/foo/" :email] :foo]]
      (is (= (match-route route (path-for route :foo :email "aaaaa@example.com"))
             {:handler :foo
              :route-params {:email "aaaaa@example.com"}}))))
  (testing "passes with regex"
    (let [route [["/foo/" [#".+\@.+\..+" :email]] :foo]]
      (is (= (match-route route (path-for route :foo :email "aaaaa@example.com"))
             {:handler :foo
              :route-params {:email "aaaaa@example.com"}})))))

Not sure if this is intended or just an oversight.

Using a regex to specify format is fine, but I'm using it together with yada and it thinks the regex is a path element.

@malcolmsparks
Copy link
Contributor

That's true. By default, bidi only allows a limited extension of
alphanumerics, specifically this regex pattern: "[A-Za-z0-9-_.]+"

The reasoning is to prevent injection attacks. This is just the case where
you need to provide your own regex.

Malcolm Sparks
Director

Email: malcolm@juxt.pro
Web: https://juxt.pro

JUXT LTD.
Software Consulting, Delivery, Training

On 22 November 2015 at 22:38, Imre Kószó notifications@github.com wrote:

I came across a situation where I needed to create an api with a path like
"/foo/by-email/aaa@example.com" where the email is a route param. It
appears bidi does not let you do that currently without a regex
specification of the email. Please see example below:

(deftest email-in-path-test
(testing "fails without regex"
(let [route [["/foo/" :email] :foo]](is %28= %28match-route route %28path-for route :foo :email))
{:handler :foo
:route-params {:email "aaaa"}}))))
(testing "passes with regex"
(let [route [["/foo/" [#".+@.+..+" :email]] :foo]](is %28= %28match-route route %28path-for route :foo :email))
{:handler :foo
:route-params {:email "aaaaa@example.com"}})))))

Not sure if this is intended or just an oversight.


Reply to this email directly or view it on GitHub
#98.

@imrekoszo
Copy link
Author

Thanks for the explanation. I opened one for yada about the related path problem: juxt/yada#41

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

No branches or pull requests

2 participants