clojure.xml/parse cannot handle filenames containing #

14 views
Skip to first unread message

Zak Wilson

unread,
Jun 23, 2010, 3:30:23 PM6/23/10
to Clojure
(clojure.xml/parse "test1.log")
works correctly, output omitted

(clojure.xml/parse "test#1.log")
Premature end of file.
[Thrown class org.xml.sax.SAXParseException]

$ mv test\#1.log test2.log

(clojure.xml/parse "test2.log")
works correctly, output omitted

test#1.log is a copy of test1.log Confirmed on Linux and Mac OS

cageface

unread,
Jun 23, 2010, 11:15:49 PM6/23/10
to Clojure
It looks like it's having trouble figuring out if "test#1.log" is a
file path or a URI.

Not sure what a real solution is but this seems to work as a
workaround:

(clojure.xml/parse (java.io.File. "test#1.log"))

Stuart Halloway

unread,
Jun 23, 2010, 11:37:32 PM6/23/10
to clo...@googlegroups.com
clojure.xml/parse is not documented to handle filenames-as-strings at all. It treats strings as URIs, deferring to the host (JVM) notion of URI as implemented in the underlying API.

I can certainly see why this would be confusing! Is there a way to make it better without violating the expectations of someone who knows the Java API and expects strings to be treated as URIs?

Stu

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Zak Wilson

unread,
Jun 24, 2010, 5:46:17 PM6/24/10
to Clojure
On Jun 23, 11:37 pm, Stuart Halloway <stuart.hallo...@gmail.com>
wrote:
> I can certainly see why this would be confusing! Is there a way to make it better without violating the expectations of someone who knows the Java API and expects strings to be treated as URIs?

Perhaps throwing an appropriately informative exception when a
filename is provided as an argument would help. It might have helped
if I'd actually read the documentation carefully, but it's easy to be
surprised when the platform's convention is different from what I'm
used to.
Reply all
Reply to author
Forward
0 new messages