This commit is contained in:
Florine W. Dekker 2019-11-10 13:42:41 +01:00
parent 3d91346cc5
commit a9309bcd4e
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "fwdekker.com",
"version": "1.8.0",
"version": "1.8.1",
"description": "The source code of [my personal website](https://fwdekker.com/).",
"author": "Felix W. Dekker",
"repository": {

View File

@ -106,6 +106,9 @@ export class FileSystem {
if (target.toString() === "/")
return this.root;
console.log("---");
console.log(target);
console.log(target.parent);
const parent = this.get(target.parent);
if (!(parent instanceof Directory) || !parent.hasNode(target.fileName))
return undefined;
@ -224,7 +227,7 @@ export class Path {
.replaceAll(/(\/+)([^./]+)(\/+)(\.\.)(\/+)/, "/") // Replace `/x/../` with `/`
.replaceAll(/\/{2,}/, "/") // Replace `//` with `/`
.replaceAll(/^\/\.\.\//, "/") // Replace `/../` at start with `/`
.replace(/(.)\/$/, "$1"); // Remove trailing `/` if not last character
.replace(/(.|\n)\/$/, "$1"); // Remove trailing `/` if not last character
const parts = this.path.split("/");
this._parent = parts.slice(0, -1).join("/");

View File

@ -35,6 +35,10 @@ describe("paths", () => {
it("interprets the given path as an absolute path", () => {
expect(new Path("dir1/file").toString()).to.equal("/dir1/file");
});
it("identifies newline characters as characters", () => {
expect(new Path("/dir/\n").toString()).to.equal("/dir/\n");
});
});
describe("parts", () => {