Merge pull request #487 from hapifhir/gg-202105-npm-case

Gg 202105 npm case
This commit is contained in:
Grahame Grieve 2021-05-04 14:34:42 +10:00 committed by GitHub
commit f60434ef79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 1 deletions

View File

@ -1459,6 +1459,23 @@ public class Utilities {
return normalizePath;
}
final static int[] illegalChars = {34, 60, 62, 124, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 58, 42, 63, 92, 47};
static {
Arrays.sort(illegalChars);
}
public static String cleanFileName(String badFileName) {
StringBuilder cleanName = new StringBuilder();
int len = badFileName.codePointCount(0, badFileName.length());
for (int i=0; i<len; i++) {
int c = badFileName.codePointAt(i);
if (Arrays.binarySearch(illegalChars, c) < 0) {
cleanName.appendCodePoint(c);
}
}
return cleanName.toString();
}
}

View File

@ -388,7 +388,7 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
if (!(new File(dir).exists()))
Utilities.createDirectory(dir);
for (Entry<String, byte[]> fe : e.getValue().getContent().entrySet()) {
String fn = Utilities.path(dir, fe.getKey());
String fn = Utilities.path(dir, Utilities.cleanFileName(fe.getKey()));
byte[] cnt = fe.getValue();
TextFile.bytesToFile(cnt, fn);
size = size + cnt.length;

View File

@ -15,9 +15,17 @@ public class CachingPackageClientTests {
CachingPackageClient client = new CachingPackageClient("http://packages.fhir.org");
Assertions.assertTrue(client.exists("hl7.fhir.r4.core", "4.0.1"));
Assertions.assertTrue(!client.exists("hl7.fhir.r4.core", "1.0.2"));
Assertions.assertTrue(client.exists("HL7.fhir.r4.core", "4.0.1"));
Assertions.assertTrue(!client.exists("hl7.fhir.nothing", "1.0.1"));
}
@Test
public void testCase() throws IOException {
CachingPackageClient client = new CachingPackageClient("http://packages.fhir.org");
Assertions.assertTrue(client.exists("kbv.basis", "1.1.3"));
Assertions.assertTrue(client.exists("KBV.Basis", "1.1.3"));
}
@Test
public void testSearch() throws IOException {
CachingPackageClient client = new CachingPackageClient("http://packages.fhir.org");

View File

@ -47,4 +47,13 @@ public class PackageCacheTests {
Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.x").version(), "3.1.1");
Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.0.x").version(), "3.0.1");
}
@Test
public void testNotCaseSensitive() throws IOException {
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
cache.clear();
Assertions.assertEquals(cache.loadPackage("KBV.Basis", "1.1.3").version(), "1.1.3");
Assertions.assertEquals(cache.loadPackage("kbv.basis", "1.1.3").version(), "1.1.3");
}
}