Skip to content
代码片段 群组 项目
未验证 提交 616f92a2 编辑于 作者: Samantha Ming's avatar Samantha Ming 提交者: GitLab
浏览文件

Merge branch 'fix-broken-file-link-pipeline-security-tab' into 'master'

Fix double line number hash on pipeline security tab

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170541



Merged-by: default avatarSamantha Ming <sming@gitlab.com>
Approved-by: default avatarSamantha Ming <sming@gitlab.com>
Reviewed-by: default avatarDavid Pisek <dpisek@gitlab.com>
Co-authored-by: default avatarLorenz van Herwaarden <lvanherwaarden@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -17,13 +17,14 @@ export default { ...@@ -17,13 +17,14 @@ export default {
computed: { computed: {
fileUrl() { fileUrl() {
const { startLine: start, endLine: end, blobPath } = this.location; const { startLine: start, endLine: end, blobPath } = this.location;
const lineNumber = end > start ? `${start}-${end}` : start;
if (!blobPath) { if (!start || blobPath.includes('#')) {
return ''; return blobPath;
} }
return `${blobPath}${lineNumber ? `#L${lineNumber}` : ''}`; const lineNumber = end > start ? `${start}-${end}` : start;
return `${blobPath}#L${lineNumber}`;
}, },
locationString() { locationString() {
const { image, file, startLine, path } = this.location; const { image, file, startLine, path } = this.location;
......
...@@ -33,15 +33,15 @@ describe('VulnerabilityPath', () => { ...@@ -33,15 +33,15 @@ describe('VulnerabilityPath', () => {
}); });
it('should display path as link blob path', () => { it('should display path as link blob path', () => {
const vulnerabilityWithBloPathAndFile = vulnerabilities[1]; const vulnerabilityWithBlobPathAndFile = vulnerabilities[1];
createWrapper({ location: vulnerabilityWithBloPathAndFile.location }); createWrapper({ location: vulnerabilityWithBlobPathAndFile.location });
expect(findVulnerabilityLink().exists()).toBe(true); expect(findVulnerabilityLink().exists()).toBe(true);
expect(findVulnerabilityLink().attributes('href')).toBe( expect(findVulnerabilityLink().attributes('href')).toBe(
`${vulnerabilityWithBloPathAndFile.location.blobPath}#L${vulnerabilityWithBloPathAndFile.location.startLine}`, `${vulnerabilityWithBlobPathAndFile.location.blobPath}#L${vulnerabilityWithBlobPathAndFile.location.startLine}`,
); );
expect(findVulnerabilityText().props()).toMatchObject({ expect(findVulnerabilityText().props()).toMatchObject({
text: `${vulnerabilityWithBloPathAndFile.location.file}:${vulnerabilityWithBloPathAndFile.location.startLine}`, text: `${vulnerabilityWithBlobPathAndFile.location.file}:${vulnerabilityWithBlobPathAndFile.location.startLine}`,
position: 'middle', position: 'middle',
}); });
}); });
...@@ -64,4 +64,41 @@ describe('VulnerabilityPath', () => { ...@@ -64,4 +64,41 @@ describe('VulnerabilityPath', () => {
createWrapper(); createWrapper();
expect(wrapper.find('*').exists()).toBe(false); expect(wrapper.find('*').exists()).toBe(false);
}); });
describe('file link', () => {
it('shows only the file name if there is no start line', () => {
createWrapper({ location: { file: 'test.txt', blobPath: 'blob_path.txt' } });
expect(findVulnerabilityLink().attributes('href')).toBe('blob_path.txt');
});
it('shows the correct line number when there is a start line', () => {
createWrapper({ location: { file: 'test.txt', startLine: 24, blobPath: 'blob.txt' } });
expect(findVulnerabilityLink().attributes('href')).toBe('blob.txt#L24');
});
it('does not append the line number when the blobPath already has a hash', () => {
const blobPath = 'blob.txt#L1';
createWrapper({ location: { file: 'test.txt', startLine: 24, blobPath } });
expect(findVulnerabilityLink().attributes('href')).toBe(blobPath);
});
it('shows the correct line numbers when there is a start and end line', () => {
createWrapper({
location: { file: 'test.txt', startLine: 24, endLine: 27, blobPath: 'blob.txt' },
});
expect(findVulnerabilityLink().attributes('href')).toBe('blob.txt#L24-27');
});
it('shows only the start line when the end line is the same', () => {
createWrapper({
location: { file: 'test.txt', startLine: 24, endLine: 24, blobPath: 'blob.txt' },
});
expect(findVulnerabilityLink().attributes('href')).toBe('blob.txt#L24');
});
});
}); });
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册