-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Cases] Escape special characters in Parent issue field of Jira connector #145610
[Cases] Escape special characters in Parent issue field of Jira connector #145610
Conversation
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
…-ref HEAD~1..HEAD --fix'
configurationUtilities, | ||
data: { | ||
fields: { | ||
summary: '[th!s^is()a-te+st-{~is*s|ue?or&and\\bye:}]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm should the characters here be escaped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it escapes only special characters, rest will be as it is. For above example the it will be: \\[th\\!s\\^is\\(\\)a\\-te\\+st\\-\\{\\~is\\*s\\|ue\\?or\\&and\\\\\\bye\\:\\}\\]
@@ -136,6 +136,9 @@ export const createExternalService = ( | |||
}, ''); | |||
}; | |||
|
|||
const escapeSpecialCharacters = (str: string) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's generally not an ideal solution to expose internal functions just for testing but could we do that here? Regex always makes me scared haha 😨 so it'd be good to have some tests around this function directly. It'll be way easier to test if we just export it from this file tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add a comment that includes this link: https://confluence.atlassian.com/jirasoftwareserver/search-syntax-for-text-fields-939938747.html
maybe something like:
These characters need to be escaped per Jira's search syntax, see for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment in a73197
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's generally not an ideal solution to expose internal functions just for testing but could we do that here? Regex always makes me scared haha 😨 so it'd be good to have some tests around this function directly. It'll be way easier to test if we just export it from this file tool.
Shall I put this function in a x-pack/plugins/stack_connectors/server/connector_types/cases/jira/utils.ts
for better access and tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in f060450
@@ -136,6 +136,9 @@ export const createExternalService = ( | |||
}, ''); | |||
}; | |||
|
|||
const escapeSpecialCharacters = (str: string) => | |||
str.replace(/[!^&*()+\-[\]\\/{}|:?~]/g, '\\\\$&')?.replace(/-/g, '\\\\x2d'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to escape unicode? I don't see it initially from searching this site: https://confluence.atlassian.com/jirasoftwareserver/search-syntax-for-text-fields-939938747.html
It'd be worth some manual testing though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need it. The encodeURIComponent
will encode the URL correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For an additional improvement could we do a check for that particular error message that we're getting and transform it into something a little more useful for the user?
Maybe something like Search input is not formatted correctly
and the include the jira error after that in the message.
@@ -443,6 +443,70 @@ describe('Jira service', () => { | |||
}); | |||
}); | |||
|
|||
test('escapes special characters from summary', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests the createIncident
function. We need to test the getIssues
function. Something like this:
test('it should escape JQL special characters', async () => {
requestMock.mockImplementation(() =>
createAxiosResponse({
data: {
issues: issuesResponse,
},
})
);
await service.getIssues('[th!s^is()a-te+st-{~is*s|ue?or&and\\bye:}]');
expect(requestMock).toHaveBeenLastCalledWith({
axios,
logger,
method: 'get',
configurationUtilities,
url: <the_url_escaped>,
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in a73197
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Janki. I don't think we need the tests for the createIncident
. We do not escape anything in the function neither we added any new logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, will remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
x-pack/plugins/stack_connectors/server/connector_types/cases/jira/service.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/stack_connectors/server/connector_types/cases/jira/service.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/stack_connectors/server/connector_types/cases/jira/service.ts
Outdated
Show resolved
Hide resolved
…com/js-jankisalvi/kibana into third-party-connector-special-chars
Made a change in So in this function we have 2 props of error response:
|
x-pack/plugins/stack_connectors/server/connector_types/cases/jira/service.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/stack_connectors/server/connector_types/cases/jira/service.ts
Outdated
Show resolved
Hide resolved
…com/js-jankisalvi/kibana into third-party-connector-special-chars
…-ref HEAD~1..HEAD --fix'
…, removed double quotes
…-ref HEAD~1..HEAD --fix'
…com/js-jankisalvi/kibana into third-party-connector-special-chars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Janki! Amazing job 🚀
💚 Build Succeeded
Metrics [docs]Unknown metric groupsESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
…ctor (elastic#145610) ## Summary Fixes elastic#131281 Escapes special characters `+ - & | ! ( ) { } [ ] ^ ~ * ? \ :` from parent issue field. **Before** ![image](https://user-images.githubusercontent.com/117571355/202526389-a3428c44-45b5-498c-98af-4ca709ae6937.png) **After** ![image](https://user-images.githubusercontent.com/117571355/202525304-5023f27c-c3df-4839-8c5d-231dcd4a74e6.png) ![image](https://user-images.githubusercontent.com/117571355/202526111-4324ce5b-ea13-4bb6-8d96-388178b1b60d.png) ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit a42314d)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
… connector (#145610) (#146009) # Backport This will backport the following commits from `main` to `8.6`: - [[Cases] Escape special characters in Parent issue field of Jira connector (#145610)](#145610) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Janki Salvi","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-22T15:06:29Z","message":"[Cases] Escape special characters in Parent issue field of Jira connector (#145610)\n\n## Summary\r\n\r\nFixes #131281\r\n \r\nEscapes special characters `+ - & | ! ( ) { } [ ] ^ ~ * ? \\ :` from\r\nparent issue field.\r\n\r\n**Before**\r\n\r\n![image](https://user-images.githubusercontent.com/117571355/202526389-a3428c44-45b5-498c-98af-4ca709ae6937.png)\r\n\r\n**After**\r\n\r\n![image](https://user-images.githubusercontent.com/117571355/202525304-5023f27c-c3df-4839-8c5d-231dcd4a74e6.png)\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/117571355/202526111-4324ce5b-ea13-4bb6-8d96-388178b1b60d.png)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"a42314d27046c34c7eebc4570f548870636ffe93","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","Feature:Cases","v8.6.0","v8.7.0"],"number":145610,"url":"https://github.com/elastic/kibana/pull/145610","mergeCommit":{"message":"[Cases] Escape special characters in Parent issue field of Jira connector (#145610)\n\n## Summary\r\n\r\nFixes #131281\r\n \r\nEscapes special characters `+ - & | ! ( ) { } [ ] ^ ~ * ? \\ :` from\r\nparent issue field.\r\n\r\n**Before**\r\n\r\n![image](https://user-images.githubusercontent.com/117571355/202526389-a3428c44-45b5-498c-98af-4ca709ae6937.png)\r\n\r\n**After**\r\n\r\n![image](https://user-images.githubusercontent.com/117571355/202525304-5023f27c-c3df-4839-8c5d-231dcd4a74e6.png)\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/117571355/202526111-4324ce5b-ea13-4bb6-8d96-388178b1b60d.png)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"a42314d27046c34c7eebc4570f548870636ffe93"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145610","number":145610,"mergeCommit":{"message":"[Cases] Escape special characters in Parent issue field of Jira connector (#145610)\n\n## Summary\r\n\r\nFixes #131281\r\n \r\nEscapes special characters `+ - & | ! ( ) { } [ ] ^ ~ * ? \\ :` from\r\nparent issue field.\r\n\r\n**Before**\r\n\r\n![image](https://user-images.githubusercontent.com/117571355/202526389-a3428c44-45b5-498c-98af-4ca709ae6937.png)\r\n\r\n**After**\r\n\r\n![image](https://user-images.githubusercontent.com/117571355/202525304-5023f27c-c3df-4839-8c5d-231dcd4a74e6.png)\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/117571355/202526111-4324ce5b-ea13-4bb6-8d96-388178b1b60d.png)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"a42314d27046c34c7eebc4570f548870636ffe93"}}]}] BACKPORT--> Co-authored-by: Janki Salvi <[email protected]>
Summary
Fixes #131281
Escapes special characters
+ - & | ! ( ) { } [ ] ^ ~ * ? \ :
from parent issue field.Before
After
Checklist