mirror of
https://github.com/laurent22/joplin.git
synced 2025-03-26 21:12:59 +02:00
parent
06d5feaa63
commit
c3df191a95
@ -411,3 +411,37 @@ describe('models/Note', function() {
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
describe('models/Note_replacePaths', function() {
|
||||
|
||||
function testResourceReplacment(body: string, pathsToTry: string[], expected: string) {
|
||||
expect(Note['replaceResourceExternalToInternalLinks_'](pathsToTry, body)).toBe(expected);
|
||||
}
|
||||
test('Basic replacement', () => {
|
||||
const body = '';
|
||||
const pathsToTry = ['file:///C:Users/Username/resources'];
|
||||
const expected = '';
|
||||
testResourceReplacment(body, pathsToTry, expected);
|
||||
});
|
||||
|
||||
test('Replacement with spaces', () => {
|
||||
const body = '';
|
||||
const pathsToTry = ['file:///C:Users/Username with spaces/resources'];
|
||||
const expected = '';
|
||||
testResourceReplacment(body, pathsToTry, expected);
|
||||
});
|
||||
|
||||
test('Replacement with Non-ASCII', () => {
|
||||
const body = '';
|
||||
const pathsToTry = ['file:///C:Users/UsernameWithéàö/resources'];
|
||||
const expected = '';
|
||||
testResourceReplacment(body, pathsToTry, expected);
|
||||
});
|
||||
|
||||
test('Replacement with Non-ASCII and spaces', () => {
|
||||
const body = '';
|
||||
const pathsToTry = ['file:///C:Users/Username With éàö/resources'];
|
||||
const expected = '';
|
||||
testResourceReplacment(body, pathsToTry, expected);
|
||||
});
|
||||
});
|
||||
|
@ -182,7 +182,7 @@ export default class Note extends BaseItem {
|
||||
|
||||
const resourceDir = toForwardSlashes(Setting.value('resourceDir'));
|
||||
|
||||
let pathsToTry = [];
|
||||
const pathsToTry = [];
|
||||
if (options.useAbsolutePaths) {
|
||||
pathsToTry.push(`file://${resourceDir}`);
|
||||
pathsToTry.push(`file:///${resourceDir}`);
|
||||
@ -192,6 +192,13 @@ export default class Note extends BaseItem {
|
||||
pathsToTry.push(Resource.baseRelativeDirectoryPath());
|
||||
}
|
||||
|
||||
body = Note.replaceResourceExternalToInternalLinks_(pathsToTry, body);
|
||||
return body;
|
||||
}
|
||||
|
||||
private static replaceResourceExternalToInternalLinks_(pathsToTry: string[], body: string) {
|
||||
// This is a moved to a separate function for the purpose of testing only
|
||||
|
||||
// We support both the escaped and unescaped versions because both
|
||||
// of those paths are valid:
|
||||
//
|
||||
@ -202,7 +209,7 @@ export default class Note extends BaseItem {
|
||||
const temp = [];
|
||||
for (const p of pathsToTry) {
|
||||
temp.push(p);
|
||||
temp.push(markdownUtils.escapeLinkUrl(p));
|
||||
temp.push(encodeURI(p));
|
||||
}
|
||||
|
||||
pathsToTry = temp;
|
||||
@ -227,7 +234,6 @@ export default class Note extends BaseItem {
|
||||
// Handles joplin://af0edffa4a60496bba1b0ba06b8fb39a
|
||||
body = body.replace(/\(joplin:\/\/([a-zA-Z0-9]{32})\)/g, '(:/$1)');
|
||||
}
|
||||
|
||||
// this.logger().debug('replaceResourceExternalToInternalLinks result', body);
|
||||
|
||||
return body;
|
||||
|
Loading…
x
Reference in New Issue
Block a user