Skip to content

Commit

Permalink
Cover fwd slashes case
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Mar 20, 2024
1 parent c4b2577 commit 0fd6e72
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ interface PathDisplayProps {
}

const PathDisplay: React.FC<PathDisplayProps> = ({ path }) => {
const formattedPath = path
// Normalize path to use a single type of separator ("/" in this case)
// The regex /[\\/]/ matches both "/" and "\" characters.
const normalizedPath = path.replace(/\\/g, "/");
const formattedPath = normalizedPath
.split("/")
.reduce<React.ReactNode[]>((acc, segment, index, array) => {
acc.push(segment);
Expand All @@ -16,7 +19,7 @@ const PathDisplay: React.FC<PathDisplayProps> = ({ path }) => {
return acc;
}, []);

return <span>{formattedPath}</span>;
return <>{formattedPath}</>;
};

export default PathDisplay;

0 comments on commit 0fd6e72

Please sign in to comment.