Fixes path, image, and bibliography issues #7

Merged
AlexKucera merged 19 commits from windows_path_fix into master 2025-11-05 09:28:22 +01:00
19 Commits
Author SHA1 Message Date
AlexKucera 68238e3db2 Refines temp directory path validation
Ensures accurate determination of whether a directory is a temporary directory by explicitly matching the full path or a subdirectory.

This change prevents potential issues related to incorrect path comparisons, especially on Windows where path variations can occur.
2025-11-05 08:51:04 +01:00
AlexKucera c7b9a8b5b8 Fixes executable path resolution on Windows
Updates the executable path resolution logic to correctly identify executables on Windows systems by using the 'where' command instead of 'which', which is not available on Windows.

This change ensures that the application can locate and execute dependencies properly, regardless of the operating system. It also uses `path.isAbsolute` to accurately determine if a user-provided path is absolute, improving the reliability of path resolution.
2025-11-05 08:50:15 +01:00
AlexKucera 207e115699 Restricts shell metacharacters in paths
Addresses a potential command injection vulnerability by tightening the validation of executable paths.

Removes brackets and curly braces from the list of disallowed shell metacharacters in paths on Windows to prevent issues when paths contain these characters. Only the metacharacters that can't appear in safe paths are disallowed.
2025-11-05 08:47:35 +01:00
AlexKucera 35a5249607 Improves remote image download protocol handling
Ensures correct protocol (HTTP/HTTPS) is used when downloading
remote images by using the parsed URL object for the request.

This fixes potential issues where the protocol might be incorrectly
determined, especially when dealing with case-insensitive URL schemes.
2025-11-05 08:33:48 +01:00
AlexKucera a9f436f972 Simplifies path normalization for Windows compatibility
Avoids double normalization of paths, which can lead to issues with Windows path handling, specifically with drive letters and forward slashes.
2025-11-05 08:32:58 +01:00
AlexKucera c788422cdf Strengthens path validation against reserved names
Enhances path validation to prevent issues caused by reserved Windows names.

The previous implementation only checked for reserved names
when the entire path matched a reserved name. This update extends
the check to ensure that no segment of the path, including the
base name without extension, matches a reserved name.

This prevents the use of reserved names, even with extensions or
within directory structures, mitigating potential security risks.
2025-11-05 08:31:44 +01:00
AlexKucera a37e8e1e40 Fixes PATH handling for Windows compatibility
Ensures that the PATH environment variable is correctly augmented with
additional paths, especially on Windows systems. It uses platform-specific
path delimiters (';' on Windows, ':' on Unix) and filters out empty segments
to prevent PATH corruption.
2025-11-05 08:29:47 +01:00
AlexKucera 1aeebed4bf Ensures proper cleanup of converter resources
Addresses potential resource leaks by ensuring that temporary
files and event listeners are properly cleaned up when the
converter is disposed. This prevents issues with multiple
conversions, especially on platforms like Windows where file
locking can occur.

The `uncaughtException` handler is removed to avoid
swallowing errors, and a flag is added to prevent double
cleanup.
2025-11-05 08:28:35 +01:00
AlexKucera 4eb52d11c0 Handles relative redirects for remote images
Ensures that relative redirect URLs are resolved against the original image URL.
This prevents issues when downloading remote images from servers that return
relative redirect paths.
2025-11-05 08:06:48 +01:00
AlexKucera 711eab4593 Handles images without extensions correctly
Ensures images without file extensions are properly handled by appending ".png" to the filename, preventing potential issues with image processing or display.

Preserves existing extensions for other image types (e.g., svg, ico, avif) without forcing a ".png" extension.
2025-11-05 08:05:40 +01:00
AlexKucera 281c02210a Add Docstrings 2025-11-05 08:03:52 +01:00
AlexKucera 7ac9e1f489 Adds unit tests for core functionalities
Adds comprehensive unit tests to improve code coverage for core functionalities: constants, paper size mapping, modal settings, security utilities, temporary directory management, and variable mapping.

This ensures that basic functionalities work as expected and enhances the reliability of the plugin.

Additionally, this commit includes a mock Obsidian API to facilitate testing in a non-Obsidian environment.
2025-11-05 08:03:24 +01:00
AlexKucera 4a0376ec2b Simplifies path handling for temp directories
Removes unnecessary conditional logic when constructing paths for temporary directories.

The logic previously checked if the plugin directory was absolute before joining it with the directory name. This check is redundant as `path.join` correctly handles both absolute and relative paths.
2025-11-04 11:16:25 +01:00
AlexKucera 1ca3669e2f Ensures correct image download order
Ensures that standard markdown images with remote URLs are processed for download after embeds and before wikilinks.

This ensures that remote URLs in the standard markdown format `![](url)` are correctly queued for download.
2025-11-04 11:15:53 +01:00
AlexKucera 6e446048d2 Refactors local path resolution
Consolidates local path resolution logic into a dedicated
`resolveLocalPath` method for improved code reuse and readability.

Improves image downloading by using the vault adapter to write
binary data, preventing potential data corruption.

This change addresses issues with image embed resolution,
especially for attachments in non-standard locations, and fixes
file overwriting during image downloads.
2025-11-04 11:14:53 +01:00
AlexKucera 2e1d2673b1 Simplifies path joining logic
Simplifies the path joining logic by leveraging the built-in `path.join` method directly.
This change removes the manual iteration and absolute path handling, resulting in more concise and readable code.

Ensures correct path handling on Windows.
2025-11-04 11:10:53 +01:00
AlexKucera 501f380644 Simplifies path handling for Windows
Refactors the code to leverage `path.join` for cross-platform path manipulation, especially improving handling of absolute paths on Windows.

Removes redundant normalizations and simplifies the logic for determining temporary directories. This change ensures consistent behavior across different operating systems and reduces code complexity.
2025-11-04 11:09:47 +01:00
AlexKucera 9ca299cafd Fixes bibliography errors
Disables Pandoc's automatic citeproc filter to prevent errors
when processing documents without a bibliography file. This
resolves issues where Pandoc incorrectly detects citation-like
patterns in markdown and attempts to generate bibliographies,
leading to "document does not contain a bibliography" errors.
2025-11-04 10:57:24 +01:00
AlexKucera 8329c9dd48 Fixes path handling and adds remote image support
Addresses issues with path construction on Windows by using `path.isAbsolute()` to correctly handle absolute paths.  Improves cross-platform compatibility in temp directory management and binary location.

Adds support for downloading and embedding remote images (http/https URLs) in markdown, enhancing content integration. Provides fallback mechanism with placeholder text upon download failure.
2025-11-04 10:55:24 +01:00