my $im = Image::Magick->new();
my $imglink;
my $imgdatalink;
- my $r = $im->Read("$srcfile\[$pagenumber]");
+ my $r = $im->Read(":$srcfile\[$pagenumber]");
error sprintf(gettext("failed to read %s: %s"), $file, $r) if $r;
if (! defined $im->Get("width") || ! defined $im->Get("height")) {
ikiwiki (3.20150611) UNRELEASED; urgency=medium
* inline: change default sort order from age to "age title" for determinism
+ * img: avoid ImageMagick misinterpreting filenames containing a colon
-- Simon McVittie <smcv@debian.org> Thu, 11 Jun 2015 08:32:35 +0100
$ identify 'screenshot_2015-06-06_18-37-53.png[0]'
screenshot_2015-06-06_18-37-53.png[0]=>screenshot_2015-06-06_18-37-53.png PNG 453x122 453x122+0+0 8-bit sRGB 11.2KB 0.000u 0:00.000
-This might be an imagemagick bug, but it's also possible that colons are interpreted somehow. Anyway, to render such images properly in ikiwiki I had to remove the colons. An easy fix is to remove ‘:’ from `wiki_file_chars`, but this can break existing installations. A better solution would be to make `IkiWiki::Plugin::img` croak on such image filenames (which anyway are currently not rendered, but `Image::Magick`'s error message is quite cryptic).
+This might be an imagemagick bug, but it's also possible that colons
+are interpreted somehow.
+
+> Yes they are: ImageMagick has syntax to force the file to be
+> interpreted as a particular format, like gif:foobar.img to
+> read foobar.img as a GIF, or to use unusual I/O patterns, like
+> fd:5. --[[smcv]]
+
+Anyway, to render such images properly in ikiwiki I had to remove
+the colons. An easy fix is to remove ‘:’ from `wiki_file_chars`,
+but this can break existing installations.
+
+> I think we should remove `:` from the default `wiki_file_chars`
+> either as soon as we have a way to handle backwards compatibility,
+> or in ikiwiki 4; but you're right that it's a compat problem,
+> so we can't just do that as a solution. --s
+
+A better solution would be to make `IkiWiki::Plugin::img` croak on
+such image filenames (which anyway are currently not rendered, but
+`Image::Magick`'s error message is quite cryptic).
+
+> Better still would be to fix the bug by escaping the filename
+> so ImageMagick treats it as just a filename. It seems the way
+> to do that is to call `Read(":hello:world.png")` instead of
+> `Read("hello:world.png")`, which I have now [[done]]. --s
ok(! system("rm -rf t/tmp; mkdir -p t/tmp/in"));
ok(! system("cp t/img/redsquare.png t/tmp/in/redsquare.png"));
+# colons in filenames are a corner case for img
+ok(! system("cp t/img/redsquare.png t/tmp/in/hello:world.png"));
+ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c.png"));
+ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c:d.png"));
+ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c:d:e:f:g:h:i:j.png"));
if ($SVGS_WORK) {
writefile("emptysquare.svg", "t/tmp/in",
[[!img redsquare.png]]
[[!img redsquare.png size=10x]]
[[!img redsquare.png size=30x50]] expecting 30x30
+[[!img hello:world.png size=x8]] expecting 8x8
+[[!img a:b:c.png size=x4]]
+[[!img a:b:c:d:e:f:g:h:i:j.png size=x6]]
$maybe_svg_img
[[!img twopages.pdf size=12x]]
[[!img twopages.pdf size=16x pagenumber=1]]
sub size($) {
my $filename = shift;
my $im = Image::Magick->new();
- my $r = $im->Read($filename);
+ my $r = $im->Read(":$filename");
return "no image" if $r;
my $w = $im->Get("width");
my $h = $im->Get("height");
is(size("$outpath/12x-twopages.png"), "12x12");
is(size("$outpath/16x-p1-twopages.png"), "16x2");
+ok($outhtml =~ /width="8" height="8".*expecting 8x8/);
+is(size("$outpath/x8-hello:world.png"), "8x8");
+is(size("$outpath/x4-a:b:c.png"), "4x4");
+is(size("$outpath/x6-a:b:c:d:e:f:g:h:i:j.png"), "6x6");
# now let's remove them again
ok(! -e "$outpath/10x-simple-svg.png");
ok(! -e "$outpath/10x-simple-pdf.png");
ok(! -e "$outpath/10x-p1-simple-pdf.png");
+ ok(! -e "$outpath/x8-hello:world.png");
+ ok(! -e "$outpath/x4-a:b:c.png");
+ ok(! -e "$outpath/x6-a:b:c:d:e:f:g:h:i:j.png");
# cleanup
ok(! system("rm -rf t/tmp"));