emscripten-core / emscripten-core/emscripten

Fetch API exception: XMLHttpRequest': String contains non ISO-8859-1 code point

Open
#19,464 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

The Fetch API throws `uncaught TypeError: Failed to execute 'open' on 'XMLHttpRequest': String contains non ISO-8859-1 code point.` in 3.1.39. The issue does not occur in 3.1.38 or earlier. This is triggered specifically by writing the `attr.requestMethod` string as per the [fetch API example](https://emscripten.org/docs/api_reference/fetch.html#introduction).

![image](https://github.com/emscripten-core/emscripten/assets/649131/855acfff-9629-4cee-9743-3a1e8c371655)

The following code triggers the issue:

```cpp
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
std::strcpy(attr.requestMethod, "GET"); // <-- problem line
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
attr.userData = &callback_data;
attr.onsuccess = download_onsuccess;
attr.onerror = download_onerror;

emscripten_fetch_t *fetch{emscripten_fetch(&attr, url.c_str())};
```

Commenting out `std::strcpy(attr.requestMethod, "GET");` gets rid of the exception. However, fetch id returned is 0 (see related issue #19463).

**Version of emscripten/emsdk:**
`commit e8b64774ff1a3ddb6a013203ced27a34e70c2d8b (HEAD -> main, tag: 3.1.39, origin/main, origin/HEAD)`
> emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.39 (https://github.com/emscripten-core/emscripten/commit/36f871819b566281d160470a1ec4515f379e9f77)
> clang version 17.0.0 (https://github.com/llvm/llvm-project c672c3fe05adbb590abc99da39143b55ad510538)
> Target: wasm32-unknown-emscripten
> Thread model: posix

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.