Merge pull request #336 from gnh1201/dev
Some checks failed
CodeQL / Analyze (javascript) (push) Has been cancelled
Deploy Jekyll with GitHub Pages dependencies preinstalled / build (push) Has been cancelled
Deploy Jekyll with GitHub Pages dependencies preinstalled / deploy (push) Has been cancelled

Add isAbsolutePath utility and update path handling
This commit is contained in:
Namhyeon Go 2025-10-13 15:17:55 +09:00 committed by GitHub
commit de08a5c527
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 5 deletions

View File

@ -171,6 +171,24 @@ function loadEnvFromArgs(args, callback) {
} }
} }
function normalizePath(path) {
if (typeof path !== "string")
return false;
return (function(s) {
s = s.trim();
return (s.charAt(0) === "\uFEFF" ? s.slice(1) : s);
})(path);
}
function isAbsolutePath(path) {
var normalizedPath = normalizePath(path);
return (/^[a-zA-Z]:[\\/]/).test(normalizedPath) ||
(/^[\\/]{2,}/).test(normalizedPath) ||
(/^\//).test(normalizedPath);
};
exports.fileExists = fileExists; exports.fileExists = fileExists;
exports.folderExists = folderExists; exports.folderExists = folderExists;
exports.fileGet = fileGet; exports.fileGet = fileGet;
@ -187,10 +205,12 @@ exports.appendFile = appendFile;
exports.rotateFile = rotateFile; exports.rotateFile = rotateFile;
exports.loadEnvFromFile = loadEnvFromFile; exports.loadEnvFromFile = loadEnvFromFile;
exports.loadEnvFromArgs = loadEnvFromArgs; exports.loadEnvFromArgs = loadEnvFromArgs;
exports.normalizePath = normalizePath;
exports.isAbsolutePath = isAbsolutePath;
exports.CdoCharset = PipeIPC.CdoCharset; 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.AUTHOR = "gnh1201@catswords.re.kr";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;

View File

@ -23,7 +23,7 @@ function Excel() {
this.open = function(filename) { this.open = function(filename) {
if (typeof filename !== "undefined") { if (typeof filename !== "undefined") {
// check type of the path // check type of the path
if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) { if (!FILE.isAbsolutePath(filename)) {
filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path
} }
if (FILE.fileExists(filename)) { if (FILE.fileExists(filename)) {
@ -128,7 +128,7 @@ function PowerPoint() {
this.open = function(filename) { this.open = function(filename) {
if (typeof filename !== "undefined") { if (typeof filename !== "undefined") {
// check type of the path // check type of the path
if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) { if (!FILE.isAbsolutePath(filename)) {
filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path
} }
if (FILE.fileExists(filename)) { if (FILE.fileExists(filename)) {
@ -210,7 +210,7 @@ function Word() {
this.open = function(filename) { this.open = function(filename) {
if (typeof filename !== "undefined") { if (typeof filename !== "undefined") {
// check type of the path // check type of the path
if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) { if (!FILE.isAbsolutePath(filename)) {
filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path
} }
if (FILE.fileExists(filename)) { if (FILE.fileExists(filename)) {
@ -227,7 +227,7 @@ exports.Excel = Excel;
exports.PowerPoint = PowerPoint; exports.PowerPoint = PowerPoint;
exports.Word = Word; 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.AUTHOR = "gnh1201@catswords.re.kr";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;