Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ public String findCanonicalInLocalCache(String canonicalUrl) {
for (String pf : listPackages()) {
if (ManagedFileAccess.file(Utilities.path(cacheFolder, pf, "package", "package.json")).exists()) {
JsonObject npm = JsonParser.parseObjectFromFile(Utilities.path(cacheFolder, pf, "package", "package.json"));
if (canonicalUrl.equals(npm.asString("canonical"))) {
if (canonicalUrl.contains(npm.asString("canonical"))) {
return npm.asString("name");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ public void testReadFromCacheOnlyWaitsForLockDelete() throws IOException, Interr
lockThread.join();
}

@Test
public void testCacheHitWithCanonicalSubstringMatch() throws IOException {
File cacheDirectory = ManagedFileAccess.fromPath(Files.createTempDirectory("fpcm-canonicalSubstringTest"));
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().withCacheFolder(cacheDirectory.getAbsolutePath()).build();

pcm.addPackageToCache("example.fhir.uv.myig", "1.2.3", this.getClass().getResourceAsStream("/npm/dummy-package.tgz"), "https://packages.fhir.org/example.fhir.uv.myig/1.2.3");

String dependsOnUri = "http://somewhere.org/fhir/uv/myig/ImplementationGuide/hl7.fhir.uv.extensions";

String npmPackageName = pcm.findCanonicalInLocalCache(dependsOnUri);
assertThat(npmPackageName).isNotNull();
assertThat(npmPackageName).isEqualTo("example.fhir.uv.myig");
}

/**
We repeat the same tests multiple times here, in order to catch very rare edge cases.
*/
Expand Down
Loading