文件
mynode/packages/tools/fuzzer/utils/randomString.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

32 行
1.1 KiB
TypeScript

import removeInvalidUtf8 from './removeInvalidUtf8';
type OnRandomInt = (low: number, high: number)=> number;
const randomString = (nextRandomInteger: OnRandomInt) => (length: number) => {
const charCodes = [];
for (let i = 0; i < length; i++) {
charCodes.push(nextRandomInteger(0, 0xFFFF));
}
let text = String.fromCharCode(...charCodes);
// Normalize to avoid differences when reading/writing content from Joplin clients.
// TODO: Can the note comparison logic be adjusted to remove some of this?
text = text.normalize();
text = text.replace(/[\r\b\f\v\0\u007F]/g, '!');
text = text.replace(/\p{C}/ug, '-'); // Other control characters
// Remove invalid UTF-8
text = removeInvalidUtf8(text);
// Attempt to work around issues related to unexpected differences in items when reading from
// the Joplin client: Remove certain invalid unicode:
if ('toWellFormed' in String.prototype && typeof String.prototype.toWellFormed === 'function') {
// toWellFormed requires Node >= v20
text = String.prototype.toWellFormed.call(text);
}
return text;
};
export default randomString;