mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
All: Fix handling of new line escaping when using external edit
This commit is contained in:
parent
86bace70a5
commit
1dd6c7dde5
@ -105,7 +105,11 @@ describe('models_BaseItem', function() {
|
||||
}));
|
||||
|
||||
it('should serialize and unserialize properties that contain new lines', asyncTest(async () => {
|
||||
const note = await Note.save({ title: 'note', source_url: '\nhttps://joplinapp.org/\n' });
|
||||
const sourceUrl = `
|
||||
https://joplinapp.org/ \\n
|
||||
`;
|
||||
|
||||
const note = await Note.save({ title: 'note', source_url: sourceUrl });
|
||||
|
||||
const noteBefore = await Note.load(note.id);
|
||||
const serialized = await Note.serialize(noteBefore);
|
||||
@ -113,4 +117,18 @@ describe('models_BaseItem', function() {
|
||||
|
||||
expect(noteAfter).toEqual(noteBefore);
|
||||
}));
|
||||
|
||||
it('should not serialize the note title and body', asyncTest(async () => {
|
||||
const note = await Note.save({ title: 'my note', body: `one line
|
||||
two line
|
||||
three line \\n no escape` });
|
||||
|
||||
const noteBefore = await Note.load(note.id);
|
||||
const serialized = await Note.serialize(noteBefore);
|
||||
expect(serialized.indexOf(`my note
|
||||
|
||||
one line
|
||||
two line
|
||||
three line \\n no escape`)).toBe(0);
|
||||
}));
|
||||
});
|
||||
|
@ -260,7 +260,13 @@ class BaseItem extends BaseModel {
|
||||
propValue = `${propValue}`;
|
||||
}
|
||||
|
||||
return propValue.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
|
||||
if (propName === 'body') return propValue;
|
||||
|
||||
return propValue
|
||||
.replace(/\\n/g, '\\\\n')
|
||||
.replace(/\\r/g, '\\\\r')
|
||||
.replace(/\n/g, '\\n')
|
||||
.replace(/\r/g, '\\r');
|
||||
}
|
||||
|
||||
static unserialize_format(type, propName, propValue) {
|
||||
@ -281,7 +287,14 @@ class BaseItem extends BaseModel {
|
||||
propValue = Database.formatValue(ItemClass.fieldType(propName), propValue);
|
||||
}
|
||||
|
||||
return typeof propValue === 'string' ? propValue.replace(/\\n/g, '\n').replace(/\\r/g, '\r') : propValue;
|
||||
if (propName === 'body') return propValue;
|
||||
|
||||
return typeof propValue === 'string' ? propValue
|
||||
.replace(/\\n/g, '\n')
|
||||
.replace(/\\r/g, '\r')
|
||||
.replace(/\\\n/g, '\\n')
|
||||
.replace(/\\\r/g, '\\r')
|
||||
: propValue;
|
||||
}
|
||||
|
||||
static async serialize(item, shownKeys = null) {
|
||||
|
Loading…
Reference in New Issue
Block a user