Skip to content

Commit 40557ca

Browse files
author
Dennis Labordus
committed
Fixed bug with CoMPAS SCL filenames of length 3.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent 6744ebb commit 40557ca

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/compas/foundation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export function getTypeFromDocName(docName: string): string {
1919
export function stripExtensionFromName(docName: string): string {
2020
let name = docName;
2121
// Check if the name includes a file extension, if the case remove it.
22-
if (name.lastIndexOf(".") == name.length - (FILE_EXTENSION_LENGTH + 1)) {
22+
if (name.length > FILE_EXTENSION_LENGTH &&
23+
name.lastIndexOf(".") == name.length - (FILE_EXTENSION_LENGTH + 1)) {
2324
name = name.substring(0, name.lastIndexOf("."));
2425
}
2526
return name

test/unit/compas/foundation.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ describe('compas-foundation', () => {
1919
expect(stripExtensionFromName(name)).to.be.equal(name);
2020
});
2121

22-
it('when name is passed with extenions the same name is returned', () => {
22+
it('when name is passed with extenions the stripped name is returned', () => {
2323
const name = 'just-some-station';
2424
const extension = 'scd';
2525
expect(stripExtensionFromName(name + '.' + extension)).to.be.equal(name);
2626
});
27+
28+
it('when name is passed with length 3 the same name is returned', () => {
29+
const name = 'sml';
30+
expect(stripExtensionFromName(name)).to.be.equal(name);
31+
});
2732
});

0 commit comments

Comments
 (0)