(#463): Don't panic if an SVG has character data outside the first element

This is an expected condition; libxml2 will detect the invalid XML
properly when it continues parsing the file.

Fixes #463
parent 18468340
Pipeline #83768 passed with stages
in 33 minutes and 3 seconds
......@@ -178,7 +178,13 @@ impl XmlState {
let context = self.context();
match context {
Context::Start => panic!("characters: XML handler stack is empty!?"),
// This is character data before the first element, i.e. something like
// <?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg"/>
// ^ note the space here
// libxml2 is not finished reading the file yet; it will emit an error
// on its own when it finishes. So, ignore this condition.
Context::Start => return,
Context::ElementCreation => self.element_creation_characters(text),
Context::XInclude(_) => (),
Context::UnsupportedXIncludeChild => (),
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="576pt" height="432pt" viewBox="0 0 576 432">
<title>gl2ps_renderer figure</title>
<desc>
Creator: GL2PS 1.4.0, (C) 1999-2017 C. Geuzaine
For: Octave
CreationDate: Tue Dec 4 22:12:34 2018
</desc>
<defs>
</defs>
<polygon fill="#ffffff" points="0,0 576,0 576,432 0,432"/>
<g>
<polygon fill="#ffffff" points="0,432 576,432 576,0 0,0" shape-rendering="crispEdges"/>
<clipPath id="cp00576432">
<polygon points="0,432 576,432 576,0 0,0"/>
</clipPath>
<g clip-path="url(#cp00576432)">
<polygon fill="#ffffff" shape-rendering="crispEdges" points="74.88,384.48 521.28,384.48 74.88,32.4"/>
<polygon fill="#ffffff" shape-rendering="crispEdges" points="521.28,384.48 521.28,32.4 74.88,32.4"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="74.88,384.48 74.88,380.015"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="74.88,32.4 74.88,36.865"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="138.651,384.48 138.651,380.015"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="138.651,32.4 138.651,36.865"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="202.423,384.48 202.423,380.015"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="202.423,32.4 202.423,36.865"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="266.194,384.48 266.194,380.015"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="266.194,32.4 266.194,36.865"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="329.966,384.48 329.966,380.015"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="329.966,32.4 329.966,36.865"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="393.737,384.48 393.737,380.015"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="393.737,32.4 393.737,36.865"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="457.509,384.48 457.509,380.015"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="457.509,32.4 457.509,36.865"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="521.28,384.48 521.28,380.015"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="521.28,32.4 521.28,36.865"/>
<text xml:space="preserve" transform="translate(71.88,400.481) rotate(-0,3,-11)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">0</tspan></text>
<text xml:space="preserve" transform="translate(135.651,400.481) rotate(-0,3,-11)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">1</tspan></text>
<text xml:space="preserve" transform="translate(199.423,400.481) rotate(-0,3,-11)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">2</tspan></text>
<text xml:space="preserve" transform="translate(263.194,400.481) rotate(-0,3,-11)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">3</tspan></text>
<text xml:space="preserve" transform="translate(326.966,400.481) rotate(-0,3,-11)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">4</tspan></text>
<text xml:space="preserve" transform="translate(390.737,400.481) rotate(-0,3,-11)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">5</tspan></text>
<text xml:space="preserve" transform="translate(454.509,400.481) rotate(-0,3,-11)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">6</tspan></text>
<text xml:space="preserve" transform="translate(518.28,400.481) rotate(-0,3,-11)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">7</tspan></text>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="74.88,384.48 79.348,384.48"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="521.28,384.48 516.812,384.48"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="74.88,296.46 79.348,296.46"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="521.28,296.46 516.812,296.46"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="74.88,208.44 79.348,208.44"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="521.28,208.44 516.812,208.44"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="74.88,120.42 79.348,120.42"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="521.28,120.42 516.812,120.42"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="74.88,32.4 79.348,32.4"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="miter" points="521.28,32.4 516.812,32.4"/>
<text xml:space="preserve" transform="translate(60.8755,389.98) rotate(-0,9,-5.5)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 3 ">-1</tspan></text>
<text xml:space="preserve" transform="translate(51.8755,301.96) rotate(-0,18,-5.5)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 3 9 12 ">-0.5</tspan></text>
<text xml:space="preserve" transform="translate(63.8755,213.94) rotate(-0,6,-5.5)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">0</tspan></text>
<text xml:space="preserve" transform="translate(54.8755,125.92) rotate(-0,15,-5.5)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 6 9 ">0.5</tspan></text>
<text xml:space="preserve" transform="translate(63.8755,37.9) rotate(-0,6,-5.5)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="10"><tspan y="-1" fill="rgb(38,38,38)" x="0 ">1</tspan></text>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="square" stroke-linejoin="miter" stroke-dasharray="16,0" points="74.88,384.48 521.28,384.48"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="square" stroke-linejoin="miter" stroke-dasharray="16,0" points="74.88,32.4 521.28,32.4"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="square" stroke-linejoin="miter" stroke-dasharray="16,0" points="74.88,384.48 74.88,32.4"/>
<polyline fill="none" stroke="#262626" stroke-width="0.5" stroke-linecap="square" stroke-linejoin="miter" stroke-dasharray="16,0" points="521.28,384.48 521.28,32.4"/>
<polyline fill="none" stroke="#0071bc" stroke-width="0.5" stroke-linecap="butt" stroke-linejoin="round" points="74.88,32.4 81.2401,34.5558 87.6003,40.9705 93.9604,51.4868 100.32,65.8474 106.681,83.7003 113.041,104.608 119.401,128.06 125.761,153.479 132.121,180.245 138.481,207.702 144.841,235.177 151.201,261.996 157.562,287.504 163.922,311.076 170.282,332.134 176.642,350.162 183.002,364.719 189.362,375.449 195.722,382.088 202.082,384.474 208.443,382.548 214.803,376.359 221.163,366.056 227.523,351.893 233.883,334.217 240.243,313.46 246.603,290.131 252.963,264.801 259.324,238.091 265.684,210.654 272.044,183.163 278.404,156.292 284.764,130.697 291.124,107.007 297.484,85.8008 303.844,67.5985 310.205,52.8458 316.565,41.9039 322.925,35.0408 329.285,32.4247 335.645,34.1197 342.005,40.0841 348.365,50.172 354.725,64.1362 361.086,81.6348 367.446,102.239 373.806,125.445 380.166,150.683 386.526,177.335 392.886,204.75 399.246,232.255 405.606,259.177 411.966,284.856 418.327,308.663 424.687,330.016 431.047,348.391 437.407,363.338 443.767,374.492 450.127,381.578 456.487,384.424 462.847,382.96 469.208,377.221 475.568,367.349"/>
<text xml:space="preserve" transform="translate(266.194,219.44) rotate(-0,-0,-11)" font-family="FreeSans" font-weight="normal" font-style="normal" font-size="20"><tspan y="-3" fill="rgb(0,0,0)" x="0 10 17 27 34 39 51 56 66 77 87 ">y(x) = cos(</tspan><tspan y="-3" fill="rgb(0,0,0)" x="94 ">&#960;</tspan><tspan y="-3" fill="rgb(0,0,0)" x="106 111 121 127 138 "> x/2)</tspan></text>
</g>
</g>
</svg>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment