1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Desktop: PDF search text: Remove NULL characters early to avoid possible sync issues (#9862)

This commit is contained in:
Henry Heino
2024-02-06 08:24:00 -08:00
committed by GitHub
parent 8b9ce9ec72
commit a906e73b22
7 changed files with 49 additions and 5 deletions

View File

@ -0,0 +1,8 @@
import replaceUnsupportedCharacters from './replaceUnsupportedCharacters';
describe('replaceUnsupportedCharacters', () => {
test('should replace NULL characters', () => {
expect(replaceUnsupportedCharacters('Test\x00...')).toBe('Test�...');
expect(replaceUnsupportedCharacters('\x00Test\x00...')).toBe('�Test�...');
});
});

View File

@ -0,0 +1,17 @@
const replaceUnsupportedCharacters = (text: string) => {
// In the past, NULL characters have caused sync and search issues.
// Because these issues are often difficult to debug, we remove these characters entirely.
//
// See
// - Sync issue: https://github.com/laurent22/joplin/issues/5046
// - Search issue: https://github.com/laurent22/joplin/issues/9775
//
// As per the commonmark spec, we replace \x00 with the replacement character.
// (see https://spec.commonmark.org/0.31.2/#insecure-characters).
//
// eslint-disable-next-line no-control-regex
return text.replace(/\x00/g, '\uFFFD');
};
export default replaceUnsupportedCharacters;