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

Empty parameters are treated as missing #431

Closed
mdesharnais opened this issue Jul 24, 2016 · 6 comments
Closed

Empty parameters are treated as missing #431

mdesharnais opened this issue Jul 24, 2016 · 6 comments
Labels
Milestone

Comments

@mdesharnais
Copy link
Contributor

Given the following server:

import org.jooby.*;

public class Main extends Jooby {
  {
    get("/test", req -> req.param("foo").toOptional().toString() + "\n");
  }

  public static void main(final String[] args) throws Throwable {
    run(Main::new, args);
  }
}

Empty parameters are treated as missing:

$ curl localhost:8080/test
Optional.empty
$ curl localhost:8080/test?foo
Optional.empty
$ curl localhost:8080/test?foo=
Optional.empty
$ curl localhost:8080/test?foo=abc
Optional[abc]

One sometime wants to distinguish between an absent and empty parameter. I believe the result should be:

  • Optional.empty
  • Optional[]
  • Optional[]
  • Optional[abc]

Any thought on this?

@jknack
Copy link
Member

jknack commented Jul 24, 2016

I introduced this change in previous release. The motivation was form submits where if you leave some field blank you get an empty string for me this should be treat as missing, simplify form validation.

What is the use case for treating empty parameter as empty list? For example:

get("/test", req -> req.param("foo").toList() + "\n");

Give you [] for ?foo or ?foo=

@wenerme
Copy link

wenerme commented Jul 24, 2016

Elasticsearch have a ?pretty to pretty format the json result.

@jknack
Copy link
Member

jknack commented Jul 24, 2016

Odd, but how an empty list will help there? Still not sure if ?pretty is a valid use case... feel empty string as optional works better in general.

@jknack
Copy link
Member

jknack commented Jul 24, 2016

well, got some issues/questions about this in the google group... think going to revert the changes I did... will that work for you guys?

@mdesharnais
Copy link
Contributor Author

Hello, I am a little bit late on the train, but @wenerme gave the exact example I was referring to: a flag to enable a functionality.

@jknack
Copy link
Member

jknack commented Jul 25, 2016

was reverted found another way of handling absent/empty string while submitting forms

👍

@jknack jknack closed this as completed in d6cf8e8 Jul 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants