Skip to content

Commit 28c3750

Browse files
committed
[fix] 修复MacOS上,检测完成后显示组件路径错误
1 parent e0d63ff commit 28c3750

File tree

7 files changed

+23
-15
lines changed

7 files changed

+23
-15
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
.vscode/opensca*
44
node_modules/
55
out/
6-
engine
6+
engine
7+
opensca-*.vsix

.vscode/settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"typescript.tsc.autoDetect": "off",
1010
"editor.defaultFormatter": "esbenp.prettier-vscode",
1111
"editor.codeActionsOnSave": {
12-
"source.fixAll": true,
13-
"source.fixAll.eslint": true,
14-
"source.organizeImports": true
12+
"source.fixAll": "explicit",
13+
"source.fixAll.eslint": "explicit",
14+
"source.organizeImports": "explicit"
1515
},
1616
"eslint.validate": ["javascript", "javascriptreact"],
1717
"eslint.options": {

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 更新记录
22

3+
## [1.0.8]
4+
5+
- 修复:修复MacOS上,检测完成后显示组件路径错误
6+
37
## [1.0.7]
48

59
- 修复:修复切换检测结果,展示窗口不能自动切换到最上层

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "OpenSCA Xcheck",
44
"publisher": "Xmirror",
55
"description": "OpenSCA Xcheck",
6-
"version": "1.0.7",
6+
"version": "1.0.8",
77
"icon": "resources/xmirror_logo.png",
88
"homepage": "https://opensca.xmirror.cn",
99
"repository": {

src/common/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,10 @@ export default class Utils {
121121
getScanPaths(): string[] {
122122
const list: ComponentDataType[] = this.getScanList();
123123
const pathList: string[] = [];
124-
124+
const splitSep = path.sep;
125125
list.forEach(item => {
126126
const path = item.paths[0];
127-
// const itemPath = path.slice(0, path.indexOf('/[')).replace(this.workspacePath.replace(/\\/g, '/'), '');
128-
const itemPath = path.slice(0, path.indexOf('\\['));
127+
const itemPath = path.slice(0, path.indexOf(splitSep + '['));
129128
if (pathList.indexOf(itemPath) === -1) {
130129
pathList.push(itemPath);
131130
}
@@ -200,11 +199,12 @@ export default class Utils {
200199
};
201200

202201
const newList = _uniqWith(list);
202+
const splitSep = path.sep;
203203
return newList.map(item => {
204204
const completePath = item.paths[0];
205-
const completeLocation = completePath.slice(0, completePath.indexOf('\\['));
206-
const location = completeLocation.replace(this.workspacePath.replace(/\\/g, '/'), '');
207-
const componentPath = completePath.slice(completePath.indexOf('\\[') + 1).replace(/\\\[/g, '->[');
205+
const completeLocation = completePath.slice(0, completePath.indexOf(splitSep + '['));
206+
const location = completeLocation.replace(this.workspacePath.replace(new RegExp(splitSep, 'g'), '/'), '');
207+
const componentPath = completePath.slice(completePath.indexOf(splitSep + '[') + 1).replace(new RegExp(splitSep, 'g'), '->');
208208
const vulList = (item.vulnerabilities || []).sort((a: VulDataType, b: VulDataType) => a.security_level_id - b.security_level_id);
209209
if (vulList.length) {
210210
item.security_level_id = vulList[0].security_level_id;
@@ -219,7 +219,7 @@ export default class Utils {
219219
...item,
220220
licenseStr: (item.licenses || []).map((itemLicense: ItemLicense) => itemLicense.name).join(','),
221221
vulnerabilities: (item.vulnerabilities || []).map(item => ({ ...item, cve_id: item.cve_id || '', cnnvd_id: item.cnnvd_id || '' })),
222-
completeLocation: this.workspacePath + '' + completeLocation.slice(completePath.indexOf('\\')),
222+
completeLocation: path.join(this.workspacePath, '../' + completeLocation),
223223
completePath,
224224
componentPath,
225225
location,

src/main/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030

3131
import Storage from '../common/storage';
3232
import { BaseDataType } from '../common/types';
33-
import { OperationProvider } from '../provider/operationProvider';
33+
import { OperationProvider } from '../provider/OperationProvider';
3434
import { ResultProvider } from '../provider/resultProvider';
3535
import Webview from '../webview';
3636

src/webview/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'path';
12
import * as vscode from 'vscode';
23
import { BaseDataType, ComponentDataType, ProjectDataType, VulDataType } from '../common/types';
34

@@ -43,10 +44,11 @@ export default class Webview {
4344
this.panel.webview.onDidReceiveMessage(
4445
(message: MessageType) => {
4546
const { command, text } = message;
47+
const splitSep = path.sep;
4648
switch (command) {
4749
case 'file':
4850
text &&
49-
vscode.workspace.openTextDocument(((text || '') as any as string).split('====').join('\\')).then(document => {
51+
vscode.workspace.openTextDocument(((text || '') as any as string).split('====').join(splitSep)).then(document => {
5052
vscode.window.showTextDocument(document);
5153
});
5254
return;
@@ -206,6 +208,7 @@ export default class Webview {
206208
* @returns {any}
207209
*/
208210
getComponentWebviewContent(baseData: null | ComponentDataType = null) {
211+
const splitSep = path.sep;
209212
if (!!baseData && baseData.paths && baseData.paths.length) {
210213
baseData.path_str = baseData.paths.map(item => `<p>* ${item}</p>`).join('');
211214
}
@@ -291,7 +294,7 @@ export default class Webview {
291294
document.getElementById('btn_location').addEventListener('click', function () {
292295
vscode.postMessage({
293296
command: 'file',
294-
text: '${baseData?.completeLocation ? baseData?.completeLocation.split('\\').join('====') : ''}'
297+
text: '${baseData?.completeLocation ? baseData?.completeLocation.split(splitSep).join('====') : ''}'
295298
});
296299
})
297300
}())

0 commit comments

Comments
 (0)