From 5c5fef4a4c72fec853355da5086c8944b1057ab7 Mon Sep 17 00:00:00 2001 From: Ryan Luker Date: Sun, 5 Dec 2021 10:24:16 -0800 Subject: [PATCH] Adjust file name normalization #351 Co-authored-by: ryanluker Co-authored-by: agfn --- src/helpers.ts | 5 ++++- test/helpers.test.ts | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/helpers.ts b/src/helpers.ts index 2f26f8c1..ae220378 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,3 +1,4 @@ +import { normalize } from "path"; /** * Finds the matching suffixes of the string, stripping off the non-matching starting characters. @@ -28,7 +29,9 @@ export function findIntersect(base: string, comparee: string): string { * @param fileName File name to remove OS specific features */ export function normalizeFileName(fileName: string): string { - let name = fileName; + // properly handle relative file path bits + // See #351 https://github.com/ryanluker/vscode-coverage-gutters/issues/351 + let name = normalize(fileName); // make file path relative and OS independent name = name.toLocaleLowerCase(); // remove all file slashes diff --git a/test/helpers.test.ts b/test/helpers.test.ts index 92914b85..3773245e 100644 --- a/test/helpers.test.ts +++ b/test/helpers.test.ts @@ -18,6 +18,10 @@ suite("helper Tests", function() { {fileName: "a/A/", expected: "a###a###"}, {fileName: "/###/", expected: "#########"}, {fileName: "\\/", expected: "######"}, + { + expected: "###home###lt###projects###libfuzz###json-c###arraylist.c", + fileName: "/home/lt/projects/libfuzz/json-c/build/../arraylist.c", + }, ].forEach((parameters) => { expect(normalizeFileName(parameters.fileName)).to.equal(parameters.expected); });