0

I am trying to write a JIRA query to query a bunch of defects. The problem I am having is that if there is a JQL keyword in the list of defects I am querying, the entire query fails and spits out the following error:

JiraError HTTP 400 - text: Error in the JQL Query: 'update' is a reserved JQL word. 
You must surround it in quotation marks to use it in a query.

My query:

jira.search_issues( 'key in ({})'.format(','.join(defects))),
                     validate_query=false, 
                     maxResults = MAX_JIRA_RESULTS )

This fails when a defect contains the word: 'update'. Now it is a bad data error, but I want to make sure the query is tolerant to malicious input.

Now the only way I can think of to make sure this bug never happens again is to make sure each defect that contains a JIRA keyword has that keyword escaped. This is obviously pretty tedious and is subject to fail if any new JQL keywords are added.

So is there a better way to do this other than escaping each JIRA keyword I find in my string? Additionally, is there an easy way in Python to get the JIRA keywords?

Thanks!

4

1 回答 1

1

首先,您可以引用传递给该特定查询的任何内容,因此您不必关心什么是保留字。例如,这有效:

key in ("abc-1","def-2")

如果您要在其中替换“更新”一词,它将消除您抱怨的特定错误……但是,不幸的是,您会得到另一个错误:The issue key 'update' for field 'key' is invalid.

幸运的是,有一个更好的解决方案。您的问题表明您正在使用问题密钥。JIRA 问题密钥始终采用以下格式:

<PROJECT>-<ISSUENUM>

其中的格式PROJECTJIRA 明确定义,即:

  • 第一个字符必须是字母,
  • 项目密钥中使用的所有字母必须来自现代罗马字母和大写字母,并且
  • 只能使用字母、数字或下划线字符。

除了将关键字列入黑名单之外,您还可以将与问题键正则表达式匹配的任何内容列入白名单并拒绝其他所有内容。

请注意,虽然 JIRA 系统管理员可以在这些准则之外更改项目正则表达式格式,但这相对不常见(并且 Atlassian 不支持在该配置中运行 JIRA)。

于 2015-01-29T19:08:48.163 回答