Skip to content

Commit

Permalink
fix: filename with multiple dots (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko authored Feb 17, 2024
1 parent 3ec7ce2 commit 119beab
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/utils/filename-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export const getResourceFileProperties = (workDir: string, resource: any): Resou

if (resource['resource-attributes'] && resource['resource-attributes']['file-name']) {
const fileNamePrefix = resource['resource-attributes']['file-name'].substr(0, 50);
fileName = fileNamePrefix.split('.')[0];
const lastIdx = fileNamePrefix.lastIndexOf('.');
fileName = lastIdx !== -1
? fileNamePrefix.slice(0, lastIdx)
: fileNamePrefix;fileNamePrefix.includes('.') ? fileNamePrefix.split('.').slice(0, -1).join('.') : fileNamePrefix;
}
fileName = applyCharacterMapSafely(fileName);
extension = applyCharacterMapSafely(extension);
Expand Down
Empty file added test/data/simple_file.dot.dat
Empty file.
4 changes: 2 additions & 2 deletions test/data/test-link-with-images-no-size.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Labels: [Baking](https://notsohumblepie.blogspot.com/search/label/Baking), [Cara

[[#|Reply]]

25. ![[./_resources/Not_So_Humble_Pie__White_Chocolate_Caramel_Cheesec.resources/Bilde-2Btatt-2B29.jpg]]
25. ![[./_resources/Not_So_Humble_Pie__White_Chocolate_Caramel_Cheesec.resources/Bilde-2Btatt-2B29.09.2010-2Bkl.-2B17.37-2B-233.jpg]]

[K.M.](https://www.blogger.com/profile/12467809348618421676)[April 15, 2010 at 12:52 PM](https://notsohumblepie.blogspot.com/2010/04/white-chocolate-caramel-cheesecake.html?showComment=1271361173923#c5274477479388401616)

Expand All @@ -290,7 +290,7 @@ Labels: [Baking](https://notsohumblepie.blogspot.com/search/label/Baking), [Cara

[[#|Reply]]

28. ![[./_resources/Not_So_Humble_Pie__White_Chocolate_Caramel_Cheesec.resources/crackcookies.jpg]]
28. ![[./_resources/Not_So_Humble_Pie__White_Chocolate_Caramel_Cheesec.resources/crackcookies.hand.jpg]]

[The Urban Baker](https://www.blogger.com/profile/02561212652465463688)[April 19, 2010 at 4:09 PM](https://notsohumblepie.blogspot.com/2010/04/white-chocolate-caramel-cheesecake.html?showComment=1271718572567#c193393323174013606)

Expand Down
4 changes: 2 additions & 2 deletions test/data/test-link-with-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Labels: [Baking](https://notsohumblepie.blogspot.com/search/label/Baking), [Cara

[[#|Reply]]

25. ![[./_resources/Not_So_Humble_Pie__White_Chocolate_Caramel_Cheesec.resources/Bilde-2Btatt-2B29.jpg\|36x36]]
25. ![[./_resources/Not_So_Humble_Pie__White_Chocolate_Caramel_Cheesec.resources/Bilde-2Btatt-2B29.09.2010-2Bkl.-2B17.37-2B-233.jpg\|36x36]]

[K.M.](https://www.blogger.com/profile/12467809348618421676)[April 15, 2010 at 12:52 PM](https://notsohumblepie.blogspot.com/2010/04/white-chocolate-caramel-cheesecake.html?showComment=1271361173923#c5274477479388401616)

Expand All @@ -290,7 +290,7 @@ Labels: [Baking](https://notsohumblepie.blogspot.com/search/label/Baking), [Cara

[[#|Reply]]

28. ![[./_resources/Not_So_Humble_Pie__White_Chocolate_Caramel_Cheesec.resources/crackcookies.jpg\|36x36]]
28. ![[./_resources/Not_So_Humble_Pie__White_Chocolate_Caramel_Cheesec.resources/crackcookies.hand.jpg\|36x36]]

[The Urban Baker](https://www.blogger.com/profile/02561212652465463688)[April 19, 2010 at 4:09 PM](https://notsohumblepie.blogspot.com/2010/04/white-chocolate-caramel-cheesecake.html?showComment=1271718572567#c193393323174013606)

Expand Down
14 changes: 12 additions & 2 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,21 @@ describe('filename', () => {
const resource = {
mime: 'image/png',
'resource-attributes': {
'file-name': 'fileName.jpg',
'file-name': 'fileName.dot.jpg',
},
};
const fileProps = utils.getResourceFileProperties('./test/data', resource);
assert.equal(fileProps.fileName, 'fileName.dot.jpg');
});
it('filename returned, exists, with dots, extendsion', () => {
const resource = {
mime: 'image/png',
'resource-attributes': {
'file-name': 'simple_file.dot.dat',
},
};
const fileProps = utils.getResourceFileProperties('./test/data', resource);
assert.equal(fileProps.fileName, 'fileName.jpg');
assert.equal(fileProps.fileName, 'simple_file.dot.1.dat');
});
it('filename returned, file already exists, no extension', () => {
const resource = {
Expand Down
2 changes: 1 addition & 1 deletion test/yarle-special-cases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ dateFormat: undefined,
);
assert.equal(
fs.existsSync(
`${__dirname}/../out/notes/test-scriptAttachment/_resources/scriptAttachment.resources/sample.scpt`,
`${__dirname}/../out/notes/test-scriptAttachment/_resources/scriptAttachment.resources/sample.pdf.scpt`,
),
true,
);
Expand Down

0 comments on commit 119beab

Please sign in to comment.