Commit f6e1f045 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'exclude-brackets-from-job-log-links' into 'master'

Exclude brackets from job log links

See merge request gitlab-org/gitlab!65888
parents 335f49ae 45dcb57d
......@@ -3,10 +3,10 @@
* https?:\/\/
*
* up until a disallowed character or whitespace
* [^"<>\\^`{|}\s]+
* [^"<>()\\^`{|}\s]+
*
* and a disallowed character or whitespace, including non-ending chars .,:;!?
* [^"<>\\^`{|}\s.,:;!?]
* [^"<>()\\^`{|}\s.,:;!?]
*/
export const linkRegex = /(https?:\/\/[^"<>\\^`{|}\s]+[^"<>\\^`{|}\s.,:;!?])/g;
export const linkRegex = /(https?:\/\/[^"<>()\\^`{|}\s]+[^"<>()\\^`{|}\s.,:;!?])/g;
export default { linkRegex };
......@@ -94,6 +94,16 @@ describe('Job Log Line', () => {
expect(findLinkAttributeByIndex(0).href).toBe(queryUrl);
});
it('renders links that have brackets `[]` in their parameters', () => {
const url = `${httpUrl}?label_name[]=frontend`;
createComponent(mockProps({ text: url }));
expect(findLine().text()).toBe(url);
expect(findLinks().at(0).text()).toBe(url);
expect(findLinks().at(0).attributes('href')).toBe(url);
});
it('renders multiple links surrounded by text', () => {
createComponent(
mockProps({ text: `Well, my HTTP url: ${httpUrl} and my HTTPS url: ${httpsUrl}` }),
......@@ -125,6 +135,26 @@ describe('Job Log Line', () => {
expect(findLinkAttributeByIndex(4).href).toBe(httpsUrl);
});
it('renders multiple links surrounded by brackets', () => {
createComponent(mockProps({ text: `(${httpUrl}) <${httpUrl}> {${httpsUrl}}` }));
expect(findLine().text()).toBe(
'(http://example.com) <http://example.com> {https://example.com}',
);
const links = findLinks();
expect(links).toHaveLength(3);
expect(links.at(0).text()).toBe(httpUrl);
expect(links.at(0).attributes('href')).toBe(httpUrl);
expect(links.at(1).text()).toBe(httpUrl);
expect(links.at(1).attributes('href')).toBe(httpUrl);
expect(links.at(2).text()).toBe(httpsUrl);
expect(links.at(2).attributes('href')).toBe(httpsUrl);
});
it('renders text with symbols in it', () => {
const text = 'apt-get update < /dev/null > /dev/null';
createComponent(mockProps({ text }));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment