diff options
author | Luca Casonato <hello@lcas.dev> | 2024-06-08 18:36:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-08 18:36:13 +0200 |
commit | c1f23c578881b85ae79b524a60160d8f4fb7151b (patch) | |
tree | c6c945fb4b42cd4ac6fae7135c7ad1039630a34e /tests/util | |
parent | 22d34f7012c48a25435b38c0c306085c614bbea7 (diff) |
fix(ext/node): lossy UTF-8 read node_modules files (#24140)
Previously various reads of files in `node_modules` would error on
invalid UTF-8. These were cases involving:
- reading package.json from Rust
- reading package.json from JS
- reading CommonJS files from JS
- reading CommonJS files from Rust (for ESM translation)
- reading ESM files from Rust
Diffstat (limited to 'tests/util')
-rw-r--r-- | tests/util/server/src/npm.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/util/server/src/npm.rs b/tests/util/server/src/npm.rs index 66b7bddcd..e7d8d96ab 100644 --- a/tests/util/server/src/npm.rs +++ b/tests/util/server/src/npm.rs @@ -226,10 +226,11 @@ fn get_npm_package( tarballs.insert(version.clone(), tarball_bytes); let package_json_path = version_folder.join("package.json"); - let package_json_text = fs::read_to_string(&package_json_path) - .with_context(|| { + let package_json_bytes = + fs::read(&package_json_path).with_context(|| { format!("Error reading package.json at {}", package_json_path) })?; + let package_json_text = String::from_utf8_lossy(&package_json_bytes); let mut version_info: serde_json::Map<String, serde_json::Value> = serde_json::from_str(&package_json_text)?; version_info.insert("dist".to_string(), dist.into()); |