mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-27 18:11:20 +00:00
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.
This commit is contained in:
parent
90806493ed
commit
7cba7895fd
17
lib/file.js
17
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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user