Skip to content

Commit

Permalink
fix: escape special characters in Parent issue filed of stack connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
js-jankisalvi committed Nov 17, 2022
1 parent c9f0f3e commit 516ab3b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,63 @@ describe('Jira service', () => {
});
});

test('escapes special characters from summary', async () => {
requestMock.mockImplementationOnce(() =>
createAxiosResponse({
data: {
capabilities: {
navigation: 'https://coolsite.net/rest/capabilities/navigation',
},
},
})
);

// getIssueType mocks
requestMock.mockImplementationOnce(() => issueTypesResponse);

// getIssueType mocks
requestMock.mockImplementationOnce(() =>
createAxiosResponse({
data: { id: '1', key: 'CK-1', fields: { summary: '[th!s^is()a-te+st-{~is*s|ue?or&and\\bye:}]', description: 'description' } },
})
);

requestMock.mockImplementationOnce(() =>
createAxiosResponse({
data: { id: '1', key: 'CK-1', fields: { created: '2020-04-27T10:59:46.202Z' } },
})
);

await service.createIncident({
incident: {
summary: '[th!s^is()a-te+st-{~is*s|ue?or&and\\bye:}]',
description: 'desc',
labels: [],
priority: 'High',
issueType: null,
parent: null,
},
});

expect(requestMock).toHaveBeenCalledWith({
axios,
url: 'https://coolsite.net/rest/api/2/issue',
logger,
method: 'post',
configurationUtilities,
data: {
fields: {
summary: '[th!s^is()a-te+st-{~is*s|ue?or&and\\bye:}]',
description: 'desc',
project: { key: 'CK' },
issuetype: { id: '10006' },
labels: [],
priority: { name: 'High' },
},
},
});
});

test('it should call request with correct arguments', async () => {
requestMock.mockImplementation(() =>
createAxiosResponse({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export const createExternalService = (
}, '');
};

const escapeSpecialCharacters = (str: string) => str.replace(/[!^&*()+\-[\]\\/{}|:?~]/g, '\\\\$&')?.replace(/-/g, '\\\\x2d');

const hasSupportForNewAPI = (capabilities: { capabilities?: {} }) =>
createMetaCapabilities.every((c) => Object.keys(capabilities?.capabilities ?? {}).includes(c));

Expand Down Expand Up @@ -498,8 +500,9 @@ export const createExternalService = (
};

const getIssues = async (title: string) => {
const modifiedTitle = escapeSpecialCharacters(title ?? '');
const query = `${searchUrl}?jql=${encodeURIComponent(
`project="${projectKey}" and summary ~"${title}"`
`project="${projectKey}" and summary ~"${modifiedTitle}"`
)}`;

try {
Expand Down

0 comments on commit 516ab3b

Please sign in to comment.