Check PATH producing code for double slashes

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the dumb-mistakes-and-gotchas category.

Last Updated: 2024-11-21

When writing functions that accept a path variable (unix or web), there is a common dumb mistake involving double slashes

e.g.

convertPathToFullUrl("/teams")

Make sure it's definition does not cause you to produce output like http://www.mysite//team. One example problem implementation is this (since it includes the path within)

export const convertPathToFullUrl = (path) => {
  const { baseUrl } = config;
  // BAD CODE
  return `${baseUrl}/${path}`;
};