0

I have the following php function:

            function checkJQL($filter) {
            $auth = "account:password";
            $URL='http://jira/rest/api/latest/search?jql='.$filter;
            echo $URL;

            //  Initiate curl
            $ch = curl_init();
            // Disable SSL verification
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            //Tell it to always go to the link
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            // Will return the response, if false it print the response
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            // Set the url
            curl_setopt($ch, CURLOPT_URL,$URL);
            //Set username and password
            curl_setopt($ch, CURLOPT_USERPWD, $auth);
            // Execute
            $result=curl_exec($ch);
            // Closing
            curl_close($ch);

            echo $result;
            // Will dump a beauty json :3
            var_dump(json_decode($result, true));
            echo "DONE";
        }

When I call this with $filter = "" It works fine, outputs everything. As soon as I insert a proper JQL query, it fails. When I enter random garbage, it works (As in I get a invalid input message), but when it's proper JQL it never works.

When I copy and paste the URL that I echo into the browser it works. An example filter I used:

"Target" = "Blah"

When I think about it, I don't actually need this to work, I just need it to know when the input isn't JQL (which it does). But I'm really curious now. Anyone have ideas on what it might be?

1 Answer 1

1

You should URL-encode the $filter.

The reason why it works with empty or random strings is because they don't have any challenging characters that need to be URL-encoded.

The reason why the URL works in the browser but not in the script is because the browser does the URL encoding.

So do the following:

$URL='http://jira/rest/api/latest/search?jql='.urlencode($filter);

Link to urlencode: http://php.net/manual/en/function.urlencode.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.