You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ponymail.apache.org by sebbASF <gi...@git.apache.org> on 2017/01/24 17:10:39 UTC

[GitHub] incubator-ponymail issue #353: Bug: useless conditional when fetching id par...

GitHub user sebbASF opened an issue:

    https://github.com/apache/incubator-ponymail/issues/353

    Bug: useless conditional when fetching id parameter

    Several Lua scripts have the following code:
    
        local eid = (get.id or ""):gsub("\"", "")
        local doc = elastic.get("mbox", eid or "hmm", true)
    
    However eid cannot be false (or nil) at this point so the 'or "hmm"' condition serves no purpose.
    
    Note that get.id only returns nil if the id parameter has not been provided at all. If id is provided, then the values are assigned as follows:
    
    ?id => "1"
    ?id= => "" (empty string)
    ?id=abc => "abc"
    
    An empty string causes ES to return error 400, which is not ideal.
    
    The following code would work better:
        local eid = (get.id or "hmm"):gsub("\"", "")
    but would still result in error 400 if the user provided "?id="
    
    The code should either throw an error for missing/unspecified id, or should ensure that only a non-empty string is passed to ES.
    
    The following sets eid = "1" unless it is provided:
        local eid = (get.id and #get.id > 0 and get.id or "1"):gsub("\"", "")


----

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-ponymail issue #353: Bug: useless conditional when fetching id par...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the issue at:

    https://github.com/apache/incubator-ponymail/issues/353


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---