feat(driver): add option to strip out lone surrogates (#29179)

https://github.com/microsoft/playwright-dotnet/issues/2819
This commit is contained in:
Max Schmitt 2024-01-29 22:14:55 +01:00 committed by GitHub
parent f4b8ff9c95
commit 4df4054f19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,7 +38,15 @@ export function runDriver() {
});
const transport = new PipeTransport(process.stdout, process.stdin);
transport.onmessage = (message: string) => dispatcherConnection.dispatch(JSON.parse(message));
dispatcherConnection.onmessage = message => transport.send(JSON.stringify(message));
// Certain Language Binding JSON parsers (e.g. .NET) do not like strings with lone surrogates.
const isJavaScriptLanguageBinding = !process.env.PW_LANG_NAME || process.env.PW_LANG_NAME === 'javascript';
const replacer = !isJavaScriptLanguageBinding && (String.prototype as any).toWellFormed ? (key: string, value: any): any => {
if (typeof value === 'string')
// @ts-expect-error
return value.toWellFormed();
return value;
} : undefined;
dispatcherConnection.onmessage = message => transport.send(JSON.stringify(message, replacer));
transport.onclose = () => {
// Drop any messages during shutdown on the floor.
dispatcherConnection.onmessage = () => {};