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.
This commit is contained in:
parent
70b76bb633
commit
f51757bd16
2 changed files with 27 additions and 20 deletions
|
@ -251,6 +251,13 @@ charStylesToDoc st = vcat $ map makeStyle $ Set.toAscList $ inlineStyles st
|
||||||
else empty
|
else empty
|
||||||
in inTags True "CharacterStyle" ([("Self", "CharacterStyle/"++s), ("Name", s)] ++ attrs') props
|
in inTags True "CharacterStyle" ([("Self", "CharacterStyle/"++s), ("Name", s)] ++ attrs') props
|
||||||
|
|
||||||
|
-- | Escape colon characters as %3a
|
||||||
|
escapeColons :: String -> String
|
||||||
|
escapeColons (x:xs)
|
||||||
|
| x == ':' = "%3a" ++ escapeColons xs
|
||||||
|
| otherwise = x : escapeColons xs
|
||||||
|
escapeColons [] = []
|
||||||
|
|
||||||
-- | Convert a list of (identifier, url) pairs to the ICML listing of hyperlinks.
|
-- | Convert a list of (identifier, url) pairs to the ICML listing of hyperlinks.
|
||||||
hyperlinksToDoc :: Hyperlink -> Doc
|
hyperlinksToDoc :: Hyperlink -> Doc
|
||||||
hyperlinksToDoc [] = empty
|
hyperlinksToDoc [] = empty
|
||||||
|
@ -259,13 +266,13 @@ hyperlinksToDoc (x:xs) = hyp x $$ hyperlinksToDoc xs
|
||||||
hyp (ident, url) = hdest $$ hlink
|
hyp (ident, url) = hdest $$ hlink
|
||||||
where
|
where
|
||||||
hdest = selfClosingTag "HyperlinkURLDestination"
|
hdest = selfClosingTag "HyperlinkURLDestination"
|
||||||
[("Self", "HyperlinkURLDestination/"++url), ("Name","link"), ("DestinationURL",url), ("DestinationUniqueKey","1")]
|
[("Self", "HyperlinkURLDestination/"++(escapeColons url)), ("Name","link"), ("DestinationURL",url), ("DestinationUniqueKey","1")] -- HyperlinkURLDestination with more than one colon crashes CS6
|
||||||
hlink = inTags True "Hyperlink" [("Self","uf-"++show ident), ("Name",url),
|
hlink = inTags True "Hyperlink" [("Self","uf-"++show ident), ("Name",url),
|
||||||
("Source","htss-"++show ident), ("Visible","true"), ("DestinationUniqueKey","1")]
|
("Source","htss-"++show ident), ("Visible","true"), ("DestinationUniqueKey","1")]
|
||||||
$ inTags True "Properties" []
|
$ inTags True "Properties" []
|
||||||
$ inTags False "BorderColor" [("type","enumeration")] (text "Black")
|
$ inTags False "BorderColor" [("type","enumeration")] (text "Black")
|
||||||
$$ (inTags False "Destination" [("type","object")]
|
$$ (inTags False "Destination" [("type","object")]
|
||||||
$ text $ "HyperlinkURLDestination/"++(escapeStringForXML url))
|
$ text $ "HyperlinkURLDestination/"++(escapeColons (escapeStringForXML url))) -- HyperlinkURLDestination with more than one colon crashes CS6
|
||||||
|
|
||||||
|
|
||||||
-- | Convert a list of Pandoc blocks to ICML.
|
-- | Convert a list of Pandoc blocks to ICML.
|
||||||
|
|
|
@ -2717,39 +2717,39 @@ These should not be escaped: \$ \\ \> \[ \{</Content>
|
||||||
</ParagraphStyleRange>
|
</ParagraphStyleRange>
|
||||||
|
|
||||||
</Story>
|
</Story>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination/http://google.com" Name="link" DestinationURL="http://google.com" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//google.com" Name="link" DestinationURL="http://google.com" DestinationUniqueKey="1" />
|
||||||
<Hyperlink Self="uf-31" Name="http://google.com" Source="htss-31" Visible="true" DestinationUniqueKey="1">
|
<Hyperlink Self="uf-31" Name="http://google.com" Source="htss-31" Visible="true" DestinationUniqueKey="1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<BorderColor type="enumeration">Black</BorderColor>
|
<BorderColor type="enumeration">Black</BorderColor>
|
||||||
<Destination type="object">HyperlinkURLDestination/http://google.com</Destination>
|
<Destination type="object">HyperlinkURLDestination/http%3a//google.com</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/" Name="link" DestinationURL="http://example.com/" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/" Name="link" DestinationURL="http://example.com/" DestinationUniqueKey="1" />
|
||||||
<Hyperlink Self="uf-30" Name="http://example.com/" Source="htss-30" Visible="true" DestinationUniqueKey="1">
|
<Hyperlink Self="uf-30" Name="http://example.com/" Source="htss-30" Visible="true" DestinationUniqueKey="1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<BorderColor type="enumeration">Black</BorderColor>
|
<BorderColor type="enumeration">Black</BorderColor>
|
||||||
<Destination type="object">HyperlinkURLDestination/http://example.com/</Destination>
|
<Destination type="object">HyperlinkURLDestination/http%3a//example.com/</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination/mailto:nobody@nowhere.net" Name="link" DestinationURL="mailto:nobody@nowhere.net" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination/mailto%3anobody@nowhere.net" Name="link" DestinationURL="mailto:nobody@nowhere.net" DestinationUniqueKey="1" />
|
||||||
<Hyperlink Self="uf-29" Name="mailto:nobody@nowhere.net" Source="htss-29" Visible="true" DestinationUniqueKey="1">
|
<Hyperlink Self="uf-29" Name="mailto:nobody@nowhere.net" Source="htss-29" Visible="true" DestinationUniqueKey="1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<BorderColor type="enumeration">Black</BorderColor>
|
<BorderColor type="enumeration">Black</BorderColor>
|
||||||
<Destination type="object">HyperlinkURLDestination/mailto:nobody@nowhere.net</Destination>
|
<Destination type="object">HyperlinkURLDestination/mailto%3anobody@nowhere.net</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/" Name="link" DestinationURL="http://example.com/" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/" Name="link" DestinationURL="http://example.com/" DestinationUniqueKey="1" />
|
||||||
<Hyperlink Self="uf-28" Name="http://example.com/" Source="htss-28" Visible="true" DestinationUniqueKey="1">
|
<Hyperlink Self="uf-28" Name="http://example.com/" Source="htss-28" Visible="true" DestinationUniqueKey="1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<BorderColor type="enumeration">Black</BorderColor>
|
<BorderColor type="enumeration">Black</BorderColor>
|
||||||
<Destination type="object">HyperlinkURLDestination/http://example.com/</Destination>
|
<Destination type="object">HyperlinkURLDestination/http%3a//example.com/</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/?foo=1&bar=2" Name="link" DestinationURL="http://example.com/?foo=1&bar=2" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/?foo=1&bar=2" Name="link" DestinationURL="http://example.com/?foo=1&bar=2" DestinationUniqueKey="1" />
|
||||||
<Hyperlink Self="uf-27" Name="http://example.com/?foo=1&bar=2" Source="htss-27" Visible="true" DestinationUniqueKey="1">
|
<Hyperlink Self="uf-27" Name="http://example.com/?foo=1&bar=2" Source="htss-27" Visible="true" DestinationUniqueKey="1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<BorderColor type="enumeration">Black</BorderColor>
|
<BorderColor type="enumeration">Black</BorderColor>
|
||||||
<Destination type="object">HyperlinkURLDestination/http://example.com/?foo=1&bar=2</Destination>
|
<Destination type="object">HyperlinkURLDestination/http%3a//example.com/?foo=1&bar=2</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination//script?foo=1&bar=2" Name="link" DestinationURL="/script?foo=1&bar=2" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination//script?foo=1&bar=2" Name="link" DestinationURL="/script?foo=1&bar=2" DestinationUniqueKey="1" />
|
||||||
|
@ -2766,18 +2766,18 @@ These should not be escaped: \$ \\ \> \[ \{</Content>
|
||||||
<Destination type="object">HyperlinkURLDestination//script?foo=1&bar=2</Destination>
|
<Destination type="object">HyperlinkURLDestination//script?foo=1&bar=2</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination/http://att.com/" Name="link" DestinationURL="http://att.com/" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//att.com/" Name="link" DestinationURL="http://att.com/" DestinationUniqueKey="1" />
|
||||||
<Hyperlink Self="uf-24" Name="http://att.com/" Source="htss-24" Visible="true" DestinationUniqueKey="1">
|
<Hyperlink Self="uf-24" Name="http://att.com/" Source="htss-24" Visible="true" DestinationUniqueKey="1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<BorderColor type="enumeration">Black</BorderColor>
|
<BorderColor type="enumeration">Black</BorderColor>
|
||||||
<Destination type="object">HyperlinkURLDestination/http://att.com/</Destination>
|
<Destination type="object">HyperlinkURLDestination/http%3a//att.com/</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/?foo=1&bar=2" Name="link" DestinationURL="http://example.com/?foo=1&bar=2" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/?foo=1&bar=2" Name="link" DestinationURL="http://example.com/?foo=1&bar=2" DestinationUniqueKey="1" />
|
||||||
<Hyperlink Self="uf-23" Name="http://example.com/?foo=1&bar=2" Source="htss-23" Visible="true" DestinationUniqueKey="1">
|
<Hyperlink Self="uf-23" Name="http://example.com/?foo=1&bar=2" Source="htss-23" Visible="true" DestinationUniqueKey="1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<BorderColor type="enumeration">Black</BorderColor>
|
<BorderColor type="enumeration">Black</BorderColor>
|
||||||
<Destination type="object">HyperlinkURLDestination/http://example.com/?foo=1&bar=2</Destination>
|
<Destination type="object">HyperlinkURLDestination/http%3a//example.com/?foo=1&bar=2</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination//url/" Name="link" DestinationURL="/url/" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination//url/" Name="link" DestinationURL="/url/" DestinationUniqueKey="1" />
|
||||||
|
@ -2857,11 +2857,11 @@ These should not be escaped: \$ \\ \> \[ \{</Content>
|
||||||
<Destination type="object">HyperlinkURLDestination/</Destination>
|
<Destination type="object">HyperlinkURLDestination/</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination/mailto:nobody@nowhere.net" Name="link" DestinationURL="mailto:nobody@nowhere.net" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination/mailto%3anobody@nowhere.net" Name="link" DestinationURL="mailto:nobody@nowhere.net" DestinationUniqueKey="1" />
|
||||||
<Hyperlink Self="uf-11" Name="mailto:nobody@nowhere.net" Source="htss-11" Visible="true" DestinationUniqueKey="1">
|
<Hyperlink Self="uf-11" Name="mailto:nobody@nowhere.net" Source="htss-11" Visible="true" DestinationUniqueKey="1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<BorderColor type="enumeration">Black</BorderColor>
|
<BorderColor type="enumeration">Black</BorderColor>
|
||||||
<Destination type="object">HyperlinkURLDestination/mailto:nobody@nowhere.net</Destination>
|
<Destination type="object">HyperlinkURLDestination/mailto%3anobody@nowhere.net</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination//url/with_underscore" Name="link" DestinationURL="/url/with_underscore" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination//url/with_underscore" Name="link" DestinationURL="/url/with_underscore" DestinationUniqueKey="1" />
|
||||||
|
@ -2913,11 +2913,11 @@ These should not be escaped: \$ \\ \> \[ \{</Content>
|
||||||
<Destination type="object">HyperlinkURLDestination//url/</Destination>
|
<Destination type="object">HyperlinkURLDestination//url/</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination/http://example.com/?foo=1&bar=2" Name="link" DestinationURL="http://example.com/?foo=1&bar=2" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination/http%3a//example.com/?foo=1&bar=2" Name="link" DestinationURL="http://example.com/?foo=1&bar=2" DestinationUniqueKey="1" />
|
||||||
<Hyperlink Self="uf-3" Name="http://example.com/?foo=1&bar=2" Source="htss-3" Visible="true" DestinationUniqueKey="1">
|
<Hyperlink Self="uf-3" Name="http://example.com/?foo=1&bar=2" Source="htss-3" Visible="true" DestinationUniqueKey="1">
|
||||||
<Properties>
|
<Properties>
|
||||||
<BorderColor type="enumeration">Black</BorderColor>
|
<BorderColor type="enumeration">Black</BorderColor>
|
||||||
<Destination type="object">HyperlinkURLDestination/http://example.com/?foo=1&bar=2</Destination>
|
<Destination type="object">HyperlinkURLDestination/http%3a//example.com/?foo=1&bar=2</Destination>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Hyperlink>
|
</Hyperlink>
|
||||||
<HyperlinkURLDestination Self="HyperlinkURLDestination//url" Name="link" DestinationURL="/url" DestinationUniqueKey="1" />
|
<HyperlinkURLDestination Self="HyperlinkURLDestination//url" Name="link" DestinationURL="/url" DestinationUniqueKey="1" />
|
||||||
|
|
Loading…
Reference in a new issue