diff --git a/src/main/java/com/pablissimo/sonar/LCOVParserImpl.java b/src/main/java/com/pablissimo/sonar/LCOVParserImpl.java index 60439d7..9ffc72d 100644 --- a/src/main/java/com/pablissimo/sonar/LCOVParserImpl.java +++ b/src/main/java/com/pablissimo/sonar/LCOVParserImpl.java @@ -163,9 +163,9 @@ private FileData loadCurrentFileData(final Map files, Strin // Try to accommodate Angular projects that, when the angular template loader's used // by checking for a ! in the filepath if the path isn't found - have a bash at seeking - // everything after the ! as a second fallback pass - if (inputFile == null && filePath.contains("!") && (filePath.indexOf("!") + 1) < filePath.length()) { - String amendedPath = filePath.substring(filePath.indexOf("!") + 1); + // everything after the last ! as a second fallback pass + if (inputFile == null && filePath.contains("!") && (filePath.lastIndexOf("!") + 1) < filePath.length()) { + String amendedPath = filePath.substring(filePath.lastIndexOf("!") + 1); LOG.debug("Failed to resolve " + filePath + " as a valid source file, so attempting " + amendedPath + " instead"); diff --git a/src/test/java/com/pablissimo/sonar/LCOVParserImplTest.java b/src/test/java/com/pablissimo/sonar/LCOVParserImplTest.java index e37a886..674732c 100644 --- a/src/test/java/com/pablissimo/sonar/LCOVParserImplTest.java +++ b/src/test/java/com/pablissimo/sonar/LCOVParserImplTest.java @@ -56,6 +56,18 @@ public void parsesAngularTemplateLoaderOutput() { assertEquals(3, c.linesToCover()); } + @Test + public void parsesAngularTemplateLoaderOutput_IfPassedThroughMultipleLoaders() { + Map coverage = executeForTestCase("angularmanybangs"); + DefaultCoverage c = (DefaultCoverage) coverage.get(this.inputFile); + + assertEquals((Integer) 3, c.hitsByLine().get(1)); + assertEquals((Integer) 0, c.hitsByLine().get(2)); + assertEquals((Integer) 1, c.hitsByLine().get(3)); + + assertEquals(3, c.linesToCover()); + } + @Test public void handlesNoContent() { Map coverage = executeForTestCase("blank"); diff --git a/src/test/resources/lcov/angularmanybangs.lcov b/src/test/resources/lcov/angularmanybangs.lcov new file mode 100644 index 0000000..45c1ad0 --- /dev/null +++ b/src/test/resources/lcov/angularmanybangs.lcov @@ -0,0 +1,5 @@ +SF:path/to/template/loader.js!path/to/some/other/loader.js!path/to/file.ts +DA:1,3 +DA:2,0 +DA:3,1 +end_of_record \ No newline at end of file