Member Junction
    Preparing search index...

    Function TrimTrailingSlashes

    • Removes every trailing / from a string, typically a base URL before a path is joined onto it.

      Linear in the length of the input. The regex //+$/ is not: on a string holding many slashes that are NOT at the end, it backtracks quadratically, which makes it a denial-of-service vector on any caller-supplied URL.

      Parameters

      • s: string

      Returns string

      TrimTrailingSlashes('http://localhost:4000///'); // 'http://localhost:4000'
      TrimTrailingSlashes('/'); // ''