Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] Fix string to uint8 array for special characters #17031

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions web/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,9 @@ export class CachedCallStack implements Disposable {
* @param data The string content.
*/
allocThenSetArgString(offset: PtrOffset, data: string): void {
const strOffset = this.allocRawBytes(data.length + 1);
this.storeRawBytes(strOffset, StringToUint8Array(data));
const dataUint8: Uint8Array = StringToUint8Array(data);
const strOffset = this.allocRawBytes(dataUint8.length);
this.storeRawBytes(strOffset, dataUint8);
this.addressToSetTargetValue.push([offset, strOffset]);
}
/**
Expand Down
11 changes: 6 additions & 5 deletions web/src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ export function isPromise(value: any): boolean {
* @returns The corresponding Uint8Array.
*/
export function StringToUint8Array(str: string): Uint8Array {
const arr = new Uint8Array(str.length + 1);
for (let i = 0; i < str.length; ++i) {
arr[i] = str.charCodeAt(i);
const arr: Uint8Array = new TextEncoder().encode(str);
const resArr = new Uint8Array(arr.length + 1);
for (let i = 0; i < arr.length; ++i) {
resArr[i] = arr[i];
}
arr[str.length] = 0;
return arr;
resArr[arr.length] = 0;
return resArr;
}

/**
Expand Down
Loading