You've already forked joplin
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:
8
packages/lib/utils/replaceUnsupportedCharacters.test.ts
Normal file
8
packages/lib/utils/replaceUnsupportedCharacters.test.ts
Normal 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�...');
|
||||
});
|
||||
});
|
17
packages/lib/utils/replaceUnsupportedCharacters.ts
Normal file
17
packages/lib/utils/replaceUnsupportedCharacters.ts
Normal 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;
|
Reference in New Issue
Block a user