Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/LaTeXML/Post/XSLT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ sub process {
if (my $icon = $params{ICON}) {
# Hmm.... what type? could be various image types
$params{ICON} = '"' . $self->copyResource($doc, $icon, undef) . '"'; }

# change directory so that files created by <exsl:document> are relative to the destination
my $destdir = $doc->getDestinationDirectory;
my $orig_cwd = pathname_cwd();
pathname_chdir($destdir);

my $newdoc = $doc->new($$self{stylesheet}->transform($doc->getDocument, %params));

pathname_chdir($orig_cwd);
Comment on lines +81 to +87
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also suggest a defensive check that the change is needed / well-defined:

Suggested change
my $destdir = $doc->getDestinationDirectory;
my $orig_cwd = pathname_cwd();
pathname_chdir($destdir);
my $newdoc = $doc->new($$self{stylesheet}->transform($doc->getDocument, %params));
pathname_chdir($orig_cwd);
my $destdir = $doc->getDestinationDirectory;
my $orig_cwd = pathname_cwd();
my $needs_cwd_change = ($destdir ne $orig_cwd) && (-d $destdir);
pathname_chdir($destdir) if $needs_cwd_change;
my $newdoc = $doc->new($$self{stylesheet}->transform($doc->getDocument, %params));
pathname_chdir($orig_cwd) if $needs_cwd_change;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we should also canonicalise the paths (especially if mixed path separators are involved) and emit an error/fatal if chdir fail.


return $newdoc; }

my $RESOURCE_INFO = { # [CONSTANT]
Expand Down