Aleph-Alpha / ts-rs

Generate TypeScript bindings from Rust types
MIT License
989 stars 99 forks source link

bug: `export::path:absolute` function fails when `TS_RS_EXPORT_DIR` is set to an absolute path and the `path_bug` test is executed #322

Closed escritorio-gustavo closed 1 month ago

escritorio-gustavo commented 1 month ago

Describe the bug Certain combinations of absolute paths and ../. path components can trick the aboslute function into doing nothing

To Reproduce

  1. Create a file in this repo at .cargo/config.toml with the following content:
    [env]
    TS_RS_EXPORT_DIR = { value = "./whatever", relative = true }
  2. Run cargo test

Why is this happening? The path ./whatever is automatically transformed into an absolute path by cargo due to the relative flag. The path_bug test checks if exporting to ../somewhere/ works. The paths are combined into something like /usr/me/../somewhere and passed into the absolute function. The absolute function, seeing the path starts at the root directory / assumes this is already an absolute path and does nothing The diff_paths function, not expecting the absolute function to return a path containing . or .., panics

Version 8.1.0