Skip to content

Commit 6ed1e03

Browse files
committed
fix(appendFile): Handle invalid file
1 parent e657463 commit 6ed1e03

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/modules/JsonArrayAppend.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { stat, open, FileHandle } from "fs/promises";
2-
import { CHARACTER } from "../constants";
2+
import { CHARACTER, ERRORS } from "../constants";
33

44
const appendToJsonArray = async (
55
filePath: string,
@@ -28,6 +28,10 @@ const appendToJsonArray = async (
2828
insertPosition +=
2929
i === 0 ? 0 : Buffer.byteLength(windowValue.slice(0, i), encoding);
3030
break searchForArrayEnd;
31+
} else if (
32+
![CHARACTER.NEW_LINE, CHARACTER.SPACE].includes(windowValue[i])
33+
) {
34+
throw new Error(ERRORS.INVALID_FILE);
3135
}
3236
}
3337
}

0 commit comments

Comments
 (0)