From 7cba7895fdd468f76619b571729edb7858728b3f Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 13 Oct 2025 14:55:10 +0900 Subject: [PATCH 1/2] Add isAbsolutePath utility and update path handling Introduced isAbsolutePath function in file.js to robustly check for absolute paths. Updated msoffice.js to use this utility for file path resolution in Excel.open, improving cross-platform compatibility and reliability. Version numbers incremented in both files. --- lib/file.js | 17 ++++++++++++++++- lib/msoffice.js | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/file.js b/lib/file.js index f312531..707545a 100644 --- a/lib/file.js +++ b/lib/file.js @@ -171,6 +171,20 @@ function loadEnvFromArgs(args, callback) { } } +function isAbsolutePath(path) { + if (typeof path !== "string") + return false; + + path = path.replace(/^\s+/, "").replace(/\s+$/, ""); + + if (path.charAt(0) === "\uFEFF") + path = path.slice(1); + + return (/^[a-zA-Z]:[\\/]/).test(path) || + (/^[\\/]{2,}/).test(path) || + (/^\//).test(path); +}; + exports.fileExists = fileExists; exports.folderExists = folderExists; exports.fileGet = fileGet; @@ -187,10 +201,11 @@ exports.appendFile = appendFile; exports.rotateFile = rotateFile; exports.loadEnvFromFile = loadEnvFromFile; exports.loadEnvFromArgs = loadEnvFromArgs; +exports.isAbsolutePath = isAbsolutePath; exports.CdoCharset = PipeIPC.CdoCharset; -exports.VERSIONINFO = "File IO Library (file.js) version 0.2.15"; +exports.VERSIONINFO = "File IO Library (file.js) version 0.2.16"; exports.AUTHOR = "gnh1201@catswords.re.kr"; exports.global = global; exports.require = global.require; diff --git a/lib/msoffice.js b/lib/msoffice.js index d33ff33..eb7c738 100644 --- a/lib/msoffice.js +++ b/lib/msoffice.js @@ -23,7 +23,7 @@ function Excel() { this.open = function(filename) { if (typeof filename !== "undefined") { // check type of the path - if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) { + if (!FILE.isAbsolutePath(filename)) { filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path } if (FILE.fileExists(filename)) { @@ -227,7 +227,7 @@ exports.Excel = Excel; exports.PowerPoint = PowerPoint; exports.Word = Word; -exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.2.1"; +exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.2.2"; exports.AUTHOR = "gnh1201@catswords.re.kr"; exports.global = global; exports.require = global.require; From b6a95a7c5055d934f0f66f70382c4c7e57f63d12 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 13 Oct 2025 15:12:52 +0900 Subject: [PATCH 2/2] Refactor path normalization and absolute path check Introduced a new normalizePath function in file.js to handle path trimming and BOM removal. Updated isAbsolutePath to use normalizePath for more robust path checking. Modified msoffice.js to use isAbsolutePath instead of manual string checks for determining absolute paths. --- lib/file.js | 19 ++++++++++++------- lib/msoffice.js | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/file.js b/lib/file.js index 707545a..1ce1c7a 100644 --- a/lib/file.js +++ b/lib/file.js @@ -171,18 +171,22 @@ function loadEnvFromArgs(args, callback) { } } -function isAbsolutePath(path) { +function normalizePath(path) { if (typeof path !== "string") return false; - path = path.replace(/^\s+/, "").replace(/\s+$/, ""); + return (function(s) { + s = s.trim(); + return (s.charAt(0) === "\uFEFF" ? s.slice(1) : s); + })(path); +} - if (path.charAt(0) === "\uFEFF") - path = path.slice(1); +function isAbsolutePath(path) { + var normalizedPath = normalizePath(path); - return (/^[a-zA-Z]:[\\/]/).test(path) || - (/^[\\/]{2,}/).test(path) || - (/^\//).test(path); + return (/^[a-zA-Z]:[\\/]/).test(normalizedPath) || + (/^[\\/]{2,}/).test(normalizedPath) || + (/^\//).test(normalizedPath); }; exports.fileExists = fileExists; @@ -201,6 +205,7 @@ exports.appendFile = appendFile; exports.rotateFile = rotateFile; exports.loadEnvFromFile = loadEnvFromFile; exports.loadEnvFromArgs = loadEnvFromArgs; +exports.normalizePath = normalizePath; exports.isAbsolutePath = isAbsolutePath; exports.CdoCharset = PipeIPC.CdoCharset; diff --git a/lib/msoffice.js b/lib/msoffice.js index eb7c738..ca31a88 100644 --- a/lib/msoffice.js +++ b/lib/msoffice.js @@ -128,7 +128,7 @@ function PowerPoint() { this.open = function(filename) { if (typeof filename !== "undefined") { // check type of the path - if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) { + if (!FILE.isAbsolutePath(filename)) { filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path } if (FILE.fileExists(filename)) { @@ -210,7 +210,7 @@ function Word() { this.open = function(filename) { if (typeof filename !== "undefined") { // check type of the path - if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) { + if (!FILE.isAbsolutePath(filename)) { filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path } if (FILE.fileExists(filename)) {