Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-1246

[PATCH] PrettyPrinter fails when removing DOCTYPE with internal DTD

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • 1.10
    • None
    • None

    Description

      This change fixes a bug with PrettyPrinter where, if the `DOCTYPE_REMOVE` option is passed and there is an internal DTD (square brackets) in the DOCTYPE, an exception will always be (incorrectly) thrown.

      I found this while using the `SVGTranscoder` and passing the hint `KEY_DOCTYPE` with value `VALUE_DOCTYPE_REMOVE`. Calling `transcode()` on it fails because of the PrettyPrinter bug. As a consequence, this bug essentially renders the SGV Transcoder useless in some scenarios.

      You can find the Pull Request here.

       

      Replication steps

      1. Create an SVGTranscoder
      2. Add a transcoding hint: (KEY_DOCTYPE, VALUE_DOCTYPE_REMOVE)
      3. Transcode using an SVG with an internal DTD in the DOCTYPE
      4. Notice an exception with description "end" is incorrectly thrown.

      The following snippet could be used to replicate this:

      import org.apache.batik.transcoder.TranscoderInput
      import org.apache.batik.transcoder.TranscoderOutput
      import org.apache.batik.transcoder.svg2svg.SVGTranscoder
      
      String svg = "<!DOCTYPE svg [<!ENTITY test \"TEST\">]><svg xmlns=\"http://www.w3.org/2000/svg\"></svg>"
      StringWriter stringWriter = new StringWriter();
      TranscoderInput input = new TranscoderInput(new StringReader(svg));
      TranscoderOutput output = new TranscoderOutput(stringWriter);
      SVGTranscoder svgTranscoder = new SVGTranscoder();
      svgTranscoder.addTranscodingHint(SVGTranscoder.KEY_DOCTYPE, SVGTranscoder.VALUE_DOCTYPE_REMOVE);
      svgTranscoder.transcode(input, output);
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            gusjc Gustavo Juan Cairo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: