elements icon indicating copy to clipboard operation
elements copied to clipboard

Reserved characters in path parameters are not encoded in Try It

Open xxdavid opened this issue 5 months ago • 0 comments

Hi and first of all, thanks for this great project! ❤️

Context

The Try It widget doesn't percent-encode reserved characters in path parameters, making API requests behave unexpectedly or fail.

Current Behavior

Path parameters containing reserved characters like /, :, ? are passed through unencoded.

For example:

  • Input: folder/file.txt in path parameter {path} for the endpoint /files/{path}
  • Result: /files/folder/file.txt (interpreted as separate path segments)
  • Expected: /files/folder%2Ffile.txt

Expected Behavior

Reserved characters in path parameter values should be percent-encoded per RFC 3986. The slash in folder/file.txt should become %2F to distinguish it from actual path separators.

Possible Workaround/Solution

Workaround: Manually encode values (replace / with %2F, etc.)

Fix: Update uriExpand function to encode parameter values:

function uriExpand(uri: string, data: Dictionary<string, string>) {
  if (!data) {
    return uri;
  }
  return uri.replace(/{([^#?]+?)}/g, (match, key) => {
    const value = data[key];
    return value ? encodeURIComponent(value) : match;
  });
}

Steps to Reproduce

  1. Use Try It on any endpoint with path parameters (e.g., /files/{path})
  2. Enter values with reserved characters: docs/readme.txt, user:pass, data?test=1
  3. Check network tab - characters remain unencoded

Environment

  • Version used: 9.0.6
  • Environment name and version: Safari 18.5
  • Operating System and version: macOS 15.5

xxdavid avatar Jul 25 '25 12:07 xxdavid