mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-08-03 23:49:48 +08:00
fix: harden URL-decoded image paths
Co-authored-by: zcqqq <10296164+zcqqq@users.noreply.github.com>
This commit is contained in:
Vendored
+17
-2
@@ -72757,8 +72757,13 @@ async function resolveImagePath(imagePath, baseDir, tempDir, logLabel = "baoyu-m
|
||||
}
|
||||
return localPath;
|
||||
}
|
||||
const resolved = import_node_path6.default.isAbsolute(imagePath) ? imagePath : import_node_path6.default.resolve(baseDir, imagePath);
|
||||
return resolveLocalWithFallback(resolved, logLabel);
|
||||
const decoded = safeDecodeImagePath(imagePath);
|
||||
const resolved = resolveAgainstBaseDir(decoded, baseDir);
|
||||
const resolvedWithFallback = resolveLocalWithFallback(resolved, logLabel);
|
||||
if (decoded === imagePath || import_node_fs5.default.existsSync(resolvedWithFallback)) {
|
||||
return resolvedWithFallback;
|
||||
}
|
||||
return resolveLocalWithFallback(resolveAgainstBaseDir(imagePath, baseDir), logLabel);
|
||||
}
|
||||
async function resolveContentImages(images, baseDir, tempDir, logLabel = "baoyu-md") {
|
||||
const resolved = [];
|
||||
@@ -72793,6 +72798,16 @@ function resolveLocalWithFallback(resolved, logLabel) {
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
function safeDecodeImagePath(imagePath) {
|
||||
try {
|
||||
return decodeURIComponent(imagePath);
|
||||
} catch {
|
||||
return imagePath;
|
||||
}
|
||||
}
|
||||
function resolveAgainstBaseDir(imagePath, baseDir) {
|
||||
return import_node_path6.default.isAbsolute(imagePath) ? imagePath : import_node_path6.default.resolve(baseDir, imagePath);
|
||||
}
|
||||
// src/mermaid-preprocess.ts
|
||||
var import_node_fs6 = __toESM(require("node:fs"));
|
||||
var import_node_path7 = __toESM(require("node:path"));
|
||||
|
||||
Vendored
+17
-2
@@ -72683,8 +72683,13 @@ async function resolveImagePath(imagePath, baseDir, tempDir, logLabel = "baoyu-m
|
||||
}
|
||||
return localPath;
|
||||
}
|
||||
const resolved = path5.isAbsolute(imagePath) ? imagePath : path5.resolve(baseDir, imagePath);
|
||||
return resolveLocalWithFallback(resolved, logLabel);
|
||||
const decoded = safeDecodeImagePath(imagePath);
|
||||
const resolved = resolveAgainstBaseDir(decoded, baseDir);
|
||||
const resolvedWithFallback = resolveLocalWithFallback(resolved, logLabel);
|
||||
if (decoded === imagePath || fs5.existsSync(resolvedWithFallback)) {
|
||||
return resolvedWithFallback;
|
||||
}
|
||||
return resolveLocalWithFallback(resolveAgainstBaseDir(imagePath, baseDir), logLabel);
|
||||
}
|
||||
async function resolveContentImages(images, baseDir, tempDir, logLabel = "baoyu-md") {
|
||||
const resolved = [];
|
||||
@@ -72719,6 +72724,16 @@ function resolveLocalWithFallback(resolved, logLabel) {
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
function safeDecodeImagePath(imagePath) {
|
||||
try {
|
||||
return decodeURIComponent(imagePath);
|
||||
} catch {
|
||||
return imagePath;
|
||||
}
|
||||
}
|
||||
function resolveAgainstBaseDir(imagePath, baseDir) {
|
||||
return path5.isAbsolute(imagePath) ? imagePath : path5.resolve(baseDir, imagePath);
|
||||
}
|
||||
// src/mermaid-preprocess.ts
|
||||
import fs6 from "node:fs";
|
||||
import path6 from "node:path";
|
||||
|
||||
Reference in New Issue
Block a user