Skip to content

Commit 8b1d835

Browse files
authored
Fix case-sensitive filename collision in LinkerPlugin (#183)
This work prevents LinkerPlugin from generating multiple case-sensitive versions of the same file, e.g. timer and Timer. It also prevents a potential issue of getFileRecord returning a brand new record each time.
1 parent 79e4077 commit 8b1d835

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

core/webdoc-template-library/src/template-plugins/LinkerPlugin.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,15 @@ function LinkerPluginShell() {
219219
* @return {LinkerFileRecord} All the data this linker has on the output file.
220220
*/
221221
getFileRecord(uri: string): LinkerFileRecord {
222-
const recordHit = this.fileRegistry.get(uri.toLowerCase());
222+
const key = uri.toLowerCase();
223+
const recordHit = this.fileRegistry.get(key);
223224

224225
if (!recordHit) {
225226
const record: LinkerFileRecord = {
226227
uriFragments: new Set<string>(),
227228
};
228229

229-
this.fileRegistry.set(uri, record);
230+
this.fileRegistry.set(key, record);
230231

231232
return record;
232233
}
@@ -446,8 +447,6 @@ function LinkerPluginShell() {
446447
createURI(preferredUri: string, outputRelative?: boolean): string {
447448
const uri = this.generateBaseURI(preferredUri);
448449

449-
this.getFileRecord(uri);
450-
451450
return this.processInternalURI(uri, {outputRelative});
452451
}
453452

@@ -520,13 +519,15 @@ function LinkerPluginShell() {
520519
// Append enough underscores to make the filename unique
521520
while (nonUnique) {
522521
if (this.fileRegistry.has(probeKey)) {
523-
probeURI += "_";
524-
probeKey += "_";
522+
probeURI = probeURI.replace(".html", "_.html");
523+
probeKey = probeKey.replace(".html", "_.html");
525524
} else {
526525
nonUnique = false;
527526
}
528527
}
529528

529+
this.getFileRecord(probeURI);
530+
530531
return probeURI;
531532
}
532533

0 commit comments

Comments
 (0)