Skip to content

Commit c2cede1

Browse files
chore: fix tests and normalize the input
1 parent 2e9002e commit c2cede1

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/common/exportsManager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class ExportsManager extends EventEmitter<ExportsManagerEvents> {
127127
public async readExport(exportName: string): Promise<string> {
128128
try {
129129
this.assertIsNotShuttingDown();
130-
exportName = decodeURIComponent(exportName);
130+
exportName = decodeAndNormalize(exportName);
131131
const exportHandle = this.storedExports[exportName];
132132
if (!exportHandle) {
133133
throw new Error("Requested export has either expired or does not exist.");
@@ -163,7 +163,7 @@ export class ExportsManager extends EventEmitter<ExportsManagerEvents> {
163163
}): Promise<AvailableExport> {
164164
try {
165165
this.assertIsNotShuttingDown();
166-
const exportNameWithExtension = ensureExtension(exportName, "json");
166+
const exportNameWithExtension = decodeAndNormalize(ensureExtension(exportName, "json"));
167167
if (this.storedExports[exportNameWithExtension]) {
168168
return Promise.reject(
169169
new Error("Export with same name is either already available or being generated.")
@@ -363,6 +363,10 @@ export class ExportsManager extends EventEmitter<ExportsManagerEvents> {
363363
}
364364
}
365365

366+
export function decodeAndNormalize(text: string): string {
367+
return decodeURIComponent(text).normalize("NFKC");
368+
}
369+
366370
/**
367371
* Ensures the path ends with the provided extension */
368372
export function ensureExtension(pathOrName: string, extension: string): string {

tests/unit/common/exportsManager.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ const exportsManagerConfig: ExportsManagerConfig = {
2525
function getExportNameAndPath({
2626
uniqueExportsId = new ObjectId().toString(),
2727
uniqueFileId = new ObjectId().toString(),
28-
database = "foo",
29-
collection = "bar",
3028
}:
3129
| {
3230
uniqueExportsId?: string;
3331
uniqueFileId?: string;
34-
database?: string;
35-
collection?: string;
3632
}
3733
| undefined = {}): {
3834
sessionExportsPath: string;
@@ -41,7 +37,7 @@ function getExportNameAndPath({
4137
exportURI: string;
4238
uniqueExportsId: string;
4339
} {
44-
const exportName = `${database}.${collection}.${uniqueFileId}.json`;
40+
const exportName = `${uniqueFileId}.json`;
4541
// This is the exports directory for a session.
4642
const sessionExportsPath = path.join(exportsPath, uniqueExportsId);
4743
const exportPath = path.join(sessionExportsPath, exportName);
@@ -243,7 +239,7 @@ describe("ExportsManager unit test", () => {
243239
});
244240

245241
it("should handle encoded name", async () => {
246-
const { exportName, exportURI } = getExportNameAndPath({ database: "some database", collection: "coll" });
242+
const { exportName, exportURI } = getExportNameAndPath({ uniqueFileId: "1FOO 2BAR" });
247243
const { cursor } = createDummyFindCursor([]);
248244
const exportAvailableNotifier = getExportAvailableNotifier(encodeURI(exportURI), manager);
249245
await manager.createJSONExport({

0 commit comments

Comments
 (0)