Skip to content

Commit 5541521

Browse files
authored
Merge pull request #803 from hashtopolis/2418-bug-unchecking-rules-when-not-in-attack-command-removes-the--r-flag
mdArray.splice correction & test
2 parents 9f2a3d7 + 8aa3798 commit 5541521

2 files changed

Lines changed: 58 additions & 5 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { FileType, JFile } from '@models/file.model';
2+
3+
import { FilesAttackTableComponent } from '@components/tables/files-attack-table/files-attack-table.component';
4+
import { CheckboxChangeEvent } from '@components/tables/ht-table/ht-table.models';
5+
6+
describe('FilesAttackTableComponent', () => {
7+
const rule = (id: number, filename: string): JFile => ({
8+
id,
9+
type: 'file',
10+
filename,
11+
size: 0,
12+
isSecret: false,
13+
fileType: FileType.RULES,
14+
accessGroupId: 1,
15+
lineCount: 0
16+
});
17+
18+
const unchecked = (row: JFile): CheckboxChangeEvent => ({
19+
row,
20+
columnType: 'CMD',
21+
checked: false
22+
});
23+
24+
// onPrepareAttack is pure, so no Angular fixture is needed for these command transformations.
25+
const component = Object.create(FilesAttackTableComponent.prototype) as FilesAttackTableComponent;
26+
27+
it('does not remove another rule flag when the unchecked rule was manually removed', () => {
28+
const result = component.onPrepareAttack(
29+
{
30+
attackCmd: '#HL# -r dive.rule',
31+
files: [9, 10]
32+
},
33+
unchecked(rule(9, 'best66.rule'))
34+
);
35+
36+
expect(result.attackCmd).toBe('#HL# -r dive.rule');
37+
expect(result.files).toEqual([10]);
38+
});
39+
40+
it('removes only the flag paired with the unchecked rule', () => {
41+
const result = component.onPrepareAttack(
42+
{
43+
attackCmd: '#HL# -r best66.rule -r dive.rule',
44+
files: [9, 10]
45+
},
46+
unchecked(rule(9, 'best66.rule'))
47+
);
48+
49+
expect(result.attackCmd).toBe('#HL# -r dive.rule');
50+
expect(result.files).toEqual([10]);
51+
});
52+
});

src/app/core/_components/tables/files-attack-table/files-attack-table.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,14 @@ export class FilesAttackTableComponent extends BaseTableComponent implements OnI
137137
}
138138

139139
if (!event.checked) {
140-
// Remove -r and filename from the command
140+
// Remove the filename and only its own preceding -r flag.
141141
const indexFileName = newCmdArray.indexOf(fileName);
142142
if (indexFileName !== -1) {
143-
newCmdArray.splice(indexFileName, 1);
144-
}
145-
if (row.fileType === 1) {
146-
newCmdArray.splice(indexFileName - 1, 1);
143+
if (row.fileType === FileType.RULES && newCmdArray[indexFileName - 1] === '-r') {
144+
newCmdArray.splice(indexFileName - 1, 2);
145+
} else {
146+
newCmdArray.splice(indexFileName, 1);
147+
}
147148
}
148149

149150
// Remove fileId from the array

0 commit comments

Comments
 (0)