Page 1 of 1

Can a uri-encoded character in a href be escaped?

Posted: Tue Mar 07, 2023 7:00 pm
by vicmortelmans
Hi,
I have a mapref with a filename containing "%2A" (which is the URI-encoded form of "*").

Code: Select all

   <mapref format="ditamap"
            href="../published/en-us/axk1438118744716.ditamap_20180406+1005+%2A/axk1438118744716_202301300844_008.ditamap"
            class="+ map/topicref mapgroup-d/mapref "/>
When opening the map containing this mapref in Oxygen, an error is given:

Code: Select all

File not found: "D:\mcmsm\published\en-us\axk1438118744716.ditamap_20180406+1005+*\axk1438118744716_202301300844_008.ditamap".
Oxygen is decoding the filename before going to the filesystem, which I don't want in this case, because on the filesystem it is in the encoded form.

Note that I also have XSLT scripts using this file, run in Saxon, and they show similar behaviour, so it seems to be default behaviour for interpreting XML to decode URI-encoded characters.

There is a workaround that seems to work in Oxygen, to double encode the character: so "%2A" becomes "%252A".

I suppose that this is the way it should be done. Just posting this (1) for anyone who has the same issue and (2) for confirmation that there's indeed no better solution, that would allow me to have the "real" filename in the href attribute in the XML file.

Best regards,
Vic

Re: Can a uri-encoded character in a href be escaped?

Posted: Wed Mar 08, 2023 5:33 am
by chrispitude
Hi Vic,

I think the workaround you described is actually the correct encoding. "%" must itself be written in escaped form, due to its use in escaped reserved characters. See:

URL encoding - Wikipedia

Re: Can a uri-encoded character in a href be escaped?

Posted: Wed Mar 08, 2023 7:53 am
by Radu
Hi Vic,
I confirm that if you have a file on disk named something like this "cop%2Ayright.dita" and you add a reference to it in the Oxygen DITA Maps Manager view using Oxygen's "Append Child->Reference" action (and not manually add a reference to it as you might have done), then the reference in the DITA Map looks like this:

Code: Select all

<topicref href="cop%252Ayright.dita"/>
So DITA references are URL-like and Oxygen escapes the original "%" to it's URL equivalent "%25".
If the original map you are editing in Oxygen comes as an export from a CMS, then the export has a bug in it if it does not escape the "%" to "%25" in the topicref name.

Regards,
Radu