зеркало из https://github.com/microsoft/CCF.git
Make bufToStr in polyfill strict, and document difference with native implementation (#5285)
This commit is contained in:
Родитель
13eac37a95
Коммит
682d7fafd5
|
@ -603,6 +603,9 @@ export interface CCF {
|
|||
|
||||
/**
|
||||
* Convert an ArrayBuffer into a string.
|
||||
*
|
||||
* Note that this function does not perform any encoding validation, and may produce
|
||||
* an invalid JS string if the input is not valid UTF-8.
|
||||
*/
|
||||
bufToStr(v: ArrayBuffer): string;
|
||||
|
||||
|
|
|
@ -489,8 +489,10 @@ class CCFPolyfill implements CCF {
|
|||
return typedArrToArrBuf(new TextEncoder().encode(s));
|
||||
}
|
||||
|
||||
// Note: this is stricter than CCF's bufToStr, as it will
|
||||
// reject buffers that are not valid UTF-8.
|
||||
bufToStr(v: ArrayBuffer): string {
|
||||
return new TextDecoder().decode(v);
|
||||
return new TextDecoder("utf-8", { fatal: true }).decode(v);
|
||||
}
|
||||
|
||||
jsonCompatibleToBuf<T extends JsonCompatible<T>>(v: T): ArrayBuffer {
|
||||
|
|
Загрузка…
Ссылка в новой задаче