Skip to content

Potential footgun in @uriencoded TS annotation #40

@flaki

Description

@flaki

Finally I figured out what felt off about the "@uriencoded" annotation that is used in the sdk: it applies to the function as a whole and changes incoming function parameters, which may be an issue in a future refactoring where the function body uses the incoming parameters for anything that is not in the URL.

While URL-encoding here is mostly a precaution, the way it happens is too opaque, and if someone doesn't understand what's going on (which is possible given annotations are a pretty obscure feature), this could easily become a nasty footgun.

Locally, I came up with using template strings for this, which are themselves one of the more-obscure features of JavaScript, but at least here it's immediately clear that the transformation applies to the URL itself:

import uriencode from './util/uriencoded';

const response = await axios.get(
  uriencode`/api/v2/template/${template}/${fnName}`,
  { baseURL: this.baseUrl }
);

I don't have a strong preference for either the TS annotation or the template string, but I would recommend rewriting the annotation to one that only applies to the API request URL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions