From 76e18ced06cd216891cfb83b76a05f066b49a623 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Thu, 12 Oct 2023 00:13:48 -0700 Subject: [PATCH 1/2] fix: Improve `cleanPath` platform compatability --- doctoc.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doctoc.js b/doctoc.js index 578dfa9..7fea302 100755 --- a/doctoc.js +++ b/doctoc.js @@ -4,13 +4,14 @@ var path = require('path') , fs = require('fs') + , os = require('os') , minimist = require('minimist') , file = require('./lib/file') , transform = require('./lib/transform') , files; function cleanPath(path) { - var homeExpanded = (path.indexOf('~') === 0) ? process.env.HOME + path.substr(1) : path; + var homeExpanded = (path.indexOf('~') === 0) ? path.join(os.homedir() + path.substr(1)) : path; // Escape all spaces return homeExpanded.replace(/\s/g, '\\ '); From 738f1cccc1e286a42c3fffe5d5298920898c69cd Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Wed, 23 Oct 2024 12:32:54 -0700 Subject: [PATCH 2/2] fix: Use of `path` --- doctoc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doctoc.js b/doctoc.js index 7fea302..184d1b2 100755 --- a/doctoc.js +++ b/doctoc.js @@ -10,8 +10,8 @@ var path = require('path') , transform = require('./lib/transform') , files; -function cleanPath(path) { - var homeExpanded = (path.indexOf('~') === 0) ? path.join(os.homedir() + path.substr(1)) : path; +function cleanPath(filepath) { + var homeExpanded = (filepath.indexOf('~') === 0) ? path.join(os.homedir(), filepath.substr(1)) : filepath; // Escape all spaces return homeExpanded.replace(/\s/g, '\\ ');