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

Escaping issue #230

Open
fa-grosch opened this issue Feb 7, 2019 · 4 comments
Open

Escaping issue #230

fa-grosch opened this issue Feb 7, 2019 · 4 comments

Comments

@fa-grosch
Copy link

fa-grosch commented Feb 7, 2019

The JqlQuery::quote method does not quote the given text correctly. In some scenarios, jira does not understand the jql query.

Jira-Version is: v7.13.0#713000-sha1:fbf4068

I build the query this way:

$jql = '(status != closed OR status changed to Closed after -10d ) AND'
    .' (summary ~ ' . \JiraRestApi\Issue\JqlQuery::quote($firstLine)
    .' OR description ~ ' . \JiraRestApi\Issue\JqlQuery::quote($firstLine) . ')';

$result = $issueService->search($jql);

For some values of $firstLine (maybe for special chars, single/double quotes, slashes or backslashes), jira responds to this with an error:

Fatal error: Uncaught JiraRestApi\JiraException: CURL HTTP Request Failed: Status Code : 400, URL:https://jira.xyz.com/rest/api/2/search
--
Error Message : {"errorMessages":["Unable to parse the text 'session_start(): Failed to read session data: files (path: /var/lib/php/session) in /var/www/service-a/public/index.php on line 14' for field 'summary'.","Unable to parse the text 'session_start(): Failed to read session data: files (path: /var/lib/php/session) in /var/www/reportd/public/index.php on line 14' for field 'description'."],"errors":{}} in /app/vendor/lesstif/php-jira-rest-client/src/JiraClient.php:257
Stack trace:
#0 /app/vendor/lesstif/php-jira-rest-client/src/Issue/IssueService.php(464): JiraRestApi\JiraClient->exec('search', '{"jql":"(status...', 'POST')
#1 /app/bin/run.php(85): JiraRestApi\Issue\IssueService->search('(status != clos...')
#2 {main}
thrown in /app/vendor/lesstif/php-jira-rest-client/src/JiraClient.php on line 257
@lesstif
Copy link
Owner

lesstif commented Feb 7, 2019

hi @fa-grosch

could you show me the full string in the $firstline variable for debugging purpose?

thanks.

@fa-grosch
Copy link
Author

Full query is:

(status != closed OR status changed to Closed after -10d ) AND (summary ~ "session_start(): Failed to read session data: files (path: /var/lib/php/session) in /var/www/service-a/public/index.php on line 14" OR description ~ "session_start(): Failed to read session data: files (path: /var/lib/php/session) in /var/www/service-a/public/index.php on line 14")

When I run it in Jira issue filter directly it results in this error:

Unable to parse the text 'session_start(): Failed to read session data: files (path: /var/lib/php/session) in /var/www/service-a/public/index.php on line 14' for field 'summary'.
Unable to parse the text 'session_start(): Failed to read session data: files (path: /var/lib/php/session) in /var/www/service-a/public/index.php on line 14' for field 'description'.

@lesstif
Copy link
Owner

lesstif commented Feb 11, 2019

hi @fa-grosch

JQL has an advanced search operator for text field search, but this library is not yet supported.

instead you can use search operator directly like this.

        $jql =<<< JQL
(status !=  closed OR status changed to Closed after -10d ) AND 
(summary ~ "index.php on line 14*" OR description ~  "index.php on line 14*")
JQL;

    $result = $issueService->search($jql);

@fa-grosch
Copy link
Author

@lesstif the value of summary/description represents the first line of a log file so its not possible to replace a specific part of it with a wildcard.
Then I think this report is more likely a feature request than a bug :)

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

No branches or pull requests

2 participants