git.iko.soy/typeable/pandoc
on master help sign in
Fix InDesign crash with URLs containing more than one colon character

Colons are valid characters in URLs, and used e.g. by the Internet Archive's Wayback Machine - a popular resource amongst researchers. When InDesign encounters a HyperlinkURLDestination with more than one colon character in it, it crashes when placing the ICML. (This was tested against CS6.) The IDML specification hints at this requirement in section 6.4.1: "The colon apppears in the Name attribute of the style, but is encoded as %3a when it appears in the Self attribute". Follow this example for all colon characters in URLs.

commitf51757bd16881b6429cccb115f36d595b80826a7 authorgohai <gottfried.haider@gmail.com> dateTue 9 Jun 2015, 15:46 (11 years ago) parent70b76bb
2 files changed+27−20
src/Text/Pandoc/Writers/ICML.hs+9−2 tests/writer.icml+18−18
src/Text/Pandoc/Writers/ICML.hs+9−2
@@ -251,6 +251,13 @@ charStylesToDoc st = vcat $ map makeStyle $ Set.toAscList $ inlineStyles st
251251 else empty
252252 in inTags True "CharacterStyle" ([("Self", "CharacterStyle/"++s), ("Name", s)] ++ attrs') props
253253
254+-- | Escape colon characters as %3a
255+escapeColons :: String -> String
256+escapeColons (x:xs)
257+ | x == ':' = "%3a" ++ escapeColons xs
258+ | otherwise = x : escapeColons xs
259+escapeColons [] = []
260+
254261-- | Convert a list of (identifier, url) pairs to the ICML listing of hyperlinks.
255262hyperlinksToDoc :: Hyperlink -> Doc
256263hyperlinksToDoc [] = empty
@@ -259,13 +266,13 @@ hyperlinksToDoc (x:xs) = hyp x $$ hyperlinksToDoc xs
259266 hyp (ident, url) = hdest $$ hlink
260267 where
261268 hdest = selfClosingTag "HyperlinkURLDestination"
262− [("Self", "HyperlinkURLDestination/"++url), ("Name","link"), ("DestinationURL",url), ("DestinationUniqueKey","1")]
269+ [("Self", "HyperlinkURLDestination/"++(escapeColons url)), ("Name","link"), ("DestinationURL",url), ("DestinationUniqueKey","1")] -- HyperlinkURLDestination with more than one colon crashes CS6
263270 hlink = inTags True "Hyperlink" [("Self","uf-"++show ident), ("Name",url),
264271 ("Source","htss-"++show ident), ("Visible","true"), ("DestinationUniqueKey","1")]
265272 $ inTags True "Properties" []
266273 $ inTags False "BorderColor" [("type","enumeration")] (text "Black")
267274 $$ (inTags False "Destination" [("type","object")]
268− $ text $ "HyperlinkURLDestination/"++(escapeStringForXML url))
275+ $ text $ "HyperlinkURLDestination/"++(escapeColons (escapeStringForXML url))) -- HyperlinkURLDestination with more than one colon crashes CS6
269276
270277
271278-- | Convert a list of Pandoc blocks to ICML.
tests/writer.icml+18−18
@@ -2717,39 +2717,39 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
27172717</ParagraphStyleRange>
27182718
27192719 </Story>
2720− <HyperlinkURLDestination Self="HyperlinkURLDestination/http://google.com" Name="link" DestinationURL="http://google.com" DestinationUniqueKey="1" />
2720+ <HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//google.com" Name="link" DestinationURL="http://google.com" DestinationUniqueKey="1" />
27212721 <Hyperlink Self="uf-31" Name="http://google.com" Source="htss-31" Visible="true" DestinationUniqueKey="1">
27222722 <Properties>
27232723 <BorderColor type="enumeration">Black</BorderColor>
2724− <Destination type="object">HyperlinkURLDestination/http://google.com</Destination>
2724+ <Destination type="object">HyperlinkURLDestination/http%3a//google.com</Destination>
27252725 </Properties>
27262726 </Hyperlink>
2727− <HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/" Name="link" DestinationURL="http://example.com/" DestinationUniqueKey="1" />
2727+ <HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/" Name="link" DestinationURL="http://example.com/" DestinationUniqueKey="1" />
27282728 <Hyperlink Self="uf-30" Name="http://example.com/" Source="htss-30" Visible="true" DestinationUniqueKey="1">
27292729 <Properties>
27302730 <BorderColor type="enumeration">Black</BorderColor>
2731− <Destination type="object">HyperlinkURLDestination/http://example.com/</Destination>
2731+ <Destination type="object">HyperlinkURLDestination/http%3a//example.com/</Destination>
27322732 </Properties>
27332733 </Hyperlink>
2734− <HyperlinkURLDestination Self="HyperlinkURLDestination/mailto:nobody@nowhere.net" Name="link" DestinationURL="mailto:nobody@nowhere.net" DestinationUniqueKey="1" />
2734+ <HyperlinkURLDestination Self="HyperlinkURLDestination/mailto%3anobody@nowhere.net" Name="link" DestinationURL="mailto:nobody@nowhere.net" DestinationUniqueKey="1" />
27352735 <Hyperlink Self="uf-29" Name="mailto:nobody@nowhere.net" Source="htss-29" Visible="true" DestinationUniqueKey="1">
27362736 <Properties>
27372737 <BorderColor type="enumeration">Black</BorderColor>
2738− <Destination type="object">HyperlinkURLDestination/mailto:nobody@nowhere.net</Destination>
2738+ <Destination type="object">HyperlinkURLDestination/mailto%3anobody@nowhere.net</Destination>
27392739 </Properties>
27402740 </Hyperlink>
2741− <HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/" Name="link" DestinationURL="http://example.com/" DestinationUniqueKey="1" />
2741+ <HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/" Name="link" DestinationURL="http://example.com/" DestinationUniqueKey="1" />
27422742 <Hyperlink Self="uf-28" Name="http://example.com/" Source="htss-28" Visible="true" DestinationUniqueKey="1">
27432743 <Properties>
27442744 <BorderColor type="enumeration">Black</BorderColor>
2745− <Destination type="object">HyperlinkURLDestination/http://example.com/</Destination>
2745+ <Destination type="object">HyperlinkURLDestination/http%3a//example.com/</Destination>
27462746 </Properties>
27472747 </Hyperlink>
2748− <HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/?foo=1&amp;bar=2" Name="link" DestinationURL="http://example.com/?foo=1&amp;bar=2" DestinationUniqueKey="1" />
2748+ <HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/?foo=1&amp;bar=2" Name="link" DestinationURL="http://example.com/?foo=1&amp;bar=2" DestinationUniqueKey="1" />
27492749 <Hyperlink Self="uf-27" Name="http://example.com/?foo=1&amp;bar=2" Source="htss-27" Visible="true" DestinationUniqueKey="1">
27502750 <Properties>
27512751 <BorderColor type="enumeration">Black</BorderColor>
2752− <Destination type="object">HyperlinkURLDestination/http://example.com/?foo=1&amp;bar=2</Destination>
2752+ <Destination type="object">HyperlinkURLDestination/http%3a//example.com/?foo=1&amp;bar=2</Destination>
27532753 </Properties>
27542754 </Hyperlink>
27552755 <HyperlinkURLDestination Self="HyperlinkURLDestination//script?foo=1&amp;bar=2" Name="link" DestinationURL="/script?foo=1&amp;bar=2" DestinationUniqueKey="1" />
@@ -2766,18 +2766,18 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
27662766 <Destination type="object">HyperlinkURLDestination//script?foo=1&amp;bar=2</Destination>
27672767 </Properties>
27682768 </Hyperlink>
2769− <HyperlinkURLDestination Self="HyperlinkURLDestination/http://att.com/" Name="link" DestinationURL="http://att.com/" DestinationUniqueKey="1" />
2769+ <HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//att.com/" Name="link" DestinationURL="http://att.com/" DestinationUniqueKey="1" />
27702770 <Hyperlink Self="uf-24" Name="http://att.com/" Source="htss-24" Visible="true" DestinationUniqueKey="1">
27712771 <Properties>
27722772 <BorderColor type="enumeration">Black</BorderColor>
2773− <Destination type="object">HyperlinkURLDestination/http://att.com/</Destination>
2773+ <Destination type="object">HyperlinkURLDestination/http%3a//att.com/</Destination>
27742774 </Properties>
27752775 </Hyperlink>
2776− <HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/?foo=1&amp;bar=2" Name="link" DestinationURL="http://example.com/?foo=1&amp;bar=2" DestinationUniqueKey="1" />
2776+ <HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/?foo=1&amp;bar=2" Name="link" DestinationURL="http://example.com/?foo=1&amp;bar=2" DestinationUniqueKey="1" />
27772777 <Hyperlink Self="uf-23" Name="http://example.com/?foo=1&amp;bar=2" Source="htss-23" Visible="true" DestinationUniqueKey="1">
27782778 <Properties>
27792779 <BorderColor type="enumeration">Black</BorderColor>
2780− <Destination type="object">HyperlinkURLDestination/http://example.com/?foo=1&amp;bar=2</Destination>
2780+ <Destination type="object">HyperlinkURLDestination/http%3a//example.com/?foo=1&amp;bar=2</Destination>
27812781 </Properties>
27822782 </Hyperlink>
27832783 <HyperlinkURLDestination Self="HyperlinkURLDestination//url/" Name="link" DestinationURL="/url/" DestinationUniqueKey="1" />
@@ -2857,11 +2857,11 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
28572857 <Destination type="object">HyperlinkURLDestination/</Destination>
28582858 </Properties>
28592859 </Hyperlink>
2860− <HyperlinkURLDestination Self="HyperlinkURLDestination/mailto:nobody@nowhere.net" Name="link" DestinationURL="mailto:nobody@nowhere.net" DestinationUniqueKey="1" />
2860+ <HyperlinkURLDestination Self="HyperlinkURLDestination/mailto%3anobody@nowhere.net" Name="link" DestinationURL="mailto:nobody@nowhere.net" DestinationUniqueKey="1" />
28612861 <Hyperlink Self="uf-11" Name="mailto:nobody@nowhere.net" Source="htss-11" Visible="true" DestinationUniqueKey="1">
28622862 <Properties>
28632863 <BorderColor type="enumeration">Black</BorderColor>
2864− <Destination type="object">HyperlinkURLDestination/mailto:nobody@nowhere.net</Destination>
2864+ <Destination type="object">HyperlinkURLDestination/mailto%3anobody@nowhere.net</Destination>
28652865 </Properties>
28662866 </Hyperlink>
28672867 <HyperlinkURLDestination Self="HyperlinkURLDestination//url/with_underscore" Name="link" DestinationURL="/url/with_underscore" DestinationUniqueKey="1" />
@@ -2913,11 +2913,11 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
29132913 <Destination type="object">HyperlinkURLDestination//url/</Destination>
29142914 </Properties>
29152915 </Hyperlink>
2916− <HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/?foo=1&amp;bar=2" Name="link" DestinationURL="http://example.com/?foo=1&amp;bar=2" DestinationUniqueKey="1" />
2916+ <HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/?foo=1&amp;bar=2" Name="link" DestinationURL="http://example.com/?foo=1&amp;bar=2" DestinationUniqueKey="1" />
29172917 <Hyperlink Self="uf-3" Name="http://example.com/?foo=1&amp;bar=2" Source="htss-3" Visible="true" DestinationUniqueKey="1">
29182918 <Properties>
29192919 <BorderColor type="enumeration">Black</BorderColor>
2920− <Destination type="object">HyperlinkURLDestination/http://example.com/?foo=1&amp;bar=2</Destination>
2920+ <Destination type="object">HyperlinkURLDestination/http%3a//example.com/?foo=1&amp;bar=2</Destination>
29212921 </Properties>
29222922 </Hyperlink>
29232923 <HyperlinkURLDestination Self="HyperlinkURLDestination//url" Name="link" DestinationURL="/url" DestinationUniqueKey="1" />