Clojure

clojure.xml parse/emit do not round-trip

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: Release 1.3
  • Component/s: None
  • Labels:
    None

Description

I'm not expecting (emit (parse x)) to produce the same characters as originally in x. (That would be canonical form.)
However, it seems reasonable to expect that (= (parse x) (parse (emit (parse x)))). That's not currently the case because of #277 and #408.
It's not currently possible to demonstrate this bug via a unit test because of #409.
This fails:

(deftest parse-and-emit-should-round-trip-data
  (are [s0]
       (let [x1 (str->xml s0)
             s2 (xml->str x1)
             x3 (str->xml s2)]
         (is (= x1 x3)))
       "<e/>"
       "<e></e>"
       "<e>content</e>"
       "<e a='attribute'/>"
       "<e a='attribute'>content</e>"
       "<e><e><e/></e></e>"
       "<e> </e>"
       "<e>&lt;&amp;&gt;</e>"))
</code></pre>
Where:
<pre><code>(defn xml->str [x]
  (with-out-str
    (xml/emit-element x)))

(defn str->xml [s]
  (xml/parse
   (ByteArrayInputStream. (.getBytes s "UTF-8"))))

Or, rather it crashes prematurely in str->xml because of #409.

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/410 Attachments: 410-emit-element-no-longer-emits-spurious-new.patch - https://www.assembla.com/spaces/clojure/documents/b6SULoLZer346_eJe5cbLr/download/b6SULoLZer346_eJe5cbLr
Hide
Assembla Importer added a comment -

bpsm said: Tests that demonstrate #410 are available at http://github.com/bpsm/test-clojure-xml.

Show
Assembla Importer added a comment - bpsm said: Tests that demonstrate #410 are available at http://github.com/bpsm/test-clojure-xml.
Hide
Assembla Importer added a comment -

stu said: Duplicated association with ticket #277 was added

Show
Assembla Importer added a comment - stu said: Duplicated association with ticket #277 was added
Hide
Assembla Importer added a comment -

chouser@n01se.net said: Please consider the solution provided by clojure.contrib.lazy-xml/emit which uses javax.xml.transform classes to fix not only these bugs (#410 and #408) but also support indent, xml-declaration, and encoding options.

Show
Assembla Importer added a comment - chouser@n01se.net said: Please consider the solution provided by clojure.contrib.lazy-xml/emit which uses javax.xml.transform classes to fix not only these bugs (#410 and #408) but also support indent, xml-declaration, and encoding options.
Hide
Stuart Halloway added a comment -

emit is not part of Clojure's public API, and we don't want to grow a public API via an issue-driven random walk. If you are interested in this issue, please chime in on the design page for a new data.xml library: http://dev.clojure.org/display/DXML/Home

Show
Stuart Halloway added a comment - emit is not part of Clojure's public API, and we don't want to grow a public API via an issue-driven random walk. If you are interested in this issue, please chime in on the design page for a new data.xml library: http://dev.clojure.org/display/DXML/Home

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: