You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
All: Fix handling of new line escaping when using external edit
This commit is contained in:
@@ -105,7 +105,11 @@ describe('models_BaseItem', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('should serialize and unserialize properties that contain new lines', asyncTest(async () => {
|
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 noteBefore = await Note.load(note.id);
|
||||||
const serialized = await Note.serialize(noteBefore);
|
const serialized = await Note.serialize(noteBefore);
|
||||||
@@ -113,4 +117,18 @@ describe('models_BaseItem', function() {
|
|||||||
|
|
||||||
expect(noteAfter).toEqual(noteBefore);
|
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}`;
|
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) {
|
static unserialize_format(type, propName, propValue) {
|
||||||
@@ -281,7 +287,14 @@ class BaseItem extends BaseModel {
|
|||||||
propValue = Database.formatValue(ItemClass.fieldType(propName), propValue);
|
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) {
|
static async serialize(item, shownKeys = null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user