xsl-list
[Top] [All Lists]

Re: [xsl] Escaping special characters for *nix file path

2012-07-28 22:40:56
On Sun, 2012-07-29 at 04:43 +0200, Lighton Phiri wrote:

/data/Sites/3218AD Eland's Bay/Bobbejaansberg/BB15/

For path above to be valid in *nix, I need to escape 'spaces', 'single
quote' with 'backslash' to get output below

/data/Sites/3218AD\ Eland\'s\ Bay/Bobbejaansberg/BB15/

Well, spaces and quotes are allowed in Unix (and Linux) filenames, so
I'm not sure what you are doing here.


I've been trying to play around with the 'replace' function and
'disable-output-escaping', but can't seem to make it work --see
snippet below.

 <xsl:value-of select="replace(replace(replace(replace(replace($filename,
' ', '\ '), '\&#40;', '\&#40;'), '&#41;', '\&#41;'), '&#91;',
'\&#91;'), '&#93;', '\&#93;')" disable-output-escaping="yes" />

This is crazy.

replace($filename, "[ '\\`&;]", "\\&")
will probably do what you want.

Or use \s instead of space if there might be newlines.

You might also need to replace " with \"

I'm guessing you are passing the filename to a program, since you for
sure don't want to put backslashes in a path.

Also watch for filenames including things
like ../../../../../../etc/passwd :-)

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--