From 3e5a1a247cc2d006bd04ffa6e09aaac2303e4fb6 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 23 Jul 2022 14:15:12 -0600 Subject: [PATCH] Fix multiple reflections mapping to the same file name I don't like this fix, but `getAlias` isn't something that should exist to begin with, so... Resolves #2012 --- CHANGELOG.md | 4 ++++ src/lib/models/reflections/abstract.ts | 11 +++++++---- src/test/converter2/issues/gh2012.ts | 6 ++++++ src/test/issueTests.ts | 8 ++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/test/converter2/issues/gh2012.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a9d36bd7..f5e1c6ef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +### Bug Fixes + +- Fixed multiple reflections mapping to the same file name on case insensitive file systems, #2012. + ## v0.23.8 (2022-07-17) ### Features diff --git a/src/lib/models/reflections/abstract.ts b/src/lib/models/reflections/abstract.ts index 6105eca25..33af2a770 100644 --- a/src/lib/models/reflections/abstract.ts +++ b/src/lib/models/reflections/abstract.ts @@ -413,6 +413,9 @@ export abstract class Reflection { if (alias === "") { alias = "reflection-" + this.id; } + // NTFS/ExFAT use uppercase, so we will too. It probably won't matter + // in this case since names will generally be valid identifiers, but to be safe... + const upperAlias = alias.toUpperCase(); let target = this as Reflection; while (target.parent && !target.hasOwnDocument) { @@ -422,12 +425,12 @@ export abstract class Reflection { target._aliases ||= new Map(); let suffix = ""; - if (!target._aliases.has(alias)) { - target._aliases.set(alias, 1); + if (!target._aliases.has(upperAlias)) { + target._aliases.set(upperAlias, 1); } else { - const count = target._aliases.get(alias)!; + const count = target._aliases.get(upperAlias)!; suffix = "-" + count.toString(); - target._aliases.set(alias, count + 1); + target._aliases.set(upperAlias, count + 1); } alias += suffix; diff --git a/src/test/converter2/issues/gh2012.ts b/src/test/converter2/issues/gh2012.ts new file mode 100644 index 000000000..f61081847 --- /dev/null +++ b/src/test/converter2/issues/gh2012.ts @@ -0,0 +1,6 @@ +export function model(): number { + return 1; +} +export function Model(): string { + return ""; +} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index b7e488b97..5adc301fc 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -665,4 +665,12 @@ export const issueTests: { equal(b.signatures![0].sources?.[0].line, 3); equal(b.signatures![0].sources?.[0].character, 0); }, + + gh2012(project) { + project.hasOwnDocument = true; + const model = query(project, "model"); + const Model = query(project, "Model"); + equal(model.getAlias(), "model"); + equal(Model.getAlias(), "Model-1"); + }, };