UNPKG

pdf-to-png-converter

Version:

Node.js utility to convert PDF file/buffer pages to PNG files/buffers. No build-time compilation required — pre-built native binaries included for all major platforms.

20 lines (19 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SEPARATOR_DESCRIPTION = void 0; exports.containsPathSeparator = containsPathSeparator; const node_path_1 = require("node:path"); // Reject only characters the host OS treats as path separators. On Windows both "\" and "/" // are separators; on POSIX only "/" is — "\" is a valid filename character there, so PDFs // such as `foo\bar.pdf` must still convert successfully when the library derives the default // page-name mask from `path.parse(pdfFile).name`. See SEC-001 in CHANGELOG / BACKLOG for the // threat model: rejecting separators is what closes the TOCTOU window on intermediate // directory components, so both the name-resolution seam (pageOrchestrator) and the write // seam (outputWriter) must apply the exact same predicate. const PATH_SEPARATOR_PATTERN = node_path_1.sep === '\\' ? /[\\/]/ : /\//; /** The separators rejected on this host, rendered for inclusion in error messages. */ exports.SEPARATOR_DESCRIPTION = node_path_1.sep === '\\' ? '"/" or "\\"' : '"/"'; /** Whether `name` contains a character the host OS treats as a path separator. */ function containsPathSeparator(name) { return PATH_SEPARATOR_PATTERN.test(name); }