Re: Fix XML handling with DOCTYPE
Ryan Lambert <ryan@rustprooflabs.com>
From: Ryan Lambert <ryan@rustprooflabs.com>
To: Chapman Flack <chap@anastigmatix.net>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@postgresql.org
Date: 2019-03-16T22:43:43Z
Lists: pgsql-hackers
Thank you both! I had glanced at that item in the commitfest but didn't notice it would fix this issue. I'll try to test/review this before the end of the month, much better than starting from scratch myself. A quick glance at the patch looks logical and looks like it should work for my use case. Thanks, Ryan Lambert On Sat, Mar 16, 2019 at 4:33 PM Chapman Flack <chap@anastigmatix.net> wrote: > On 03/16/19 17:21, Tom Lane wrote: > > Chapman Flack <chap@anastigmatix.net> writes: > >> On 03/16/19 16:55, Tom Lane wrote: > >>> What do you think of the idea I just posted about parsing off the > DOCTYPE > >>> thing for ourselves, and not letting libxml see it? > > > >> The principled way of doing that would be to pre-parse to find a > DOCTYPE, > >> and if there is one, leave it there and parse the input as we do for > >> 'document'. Per XML, if there is a DOCTYPE, the document must satisfy > >> the 'document' syntax requirements, and per SQL/XML:2006-and-later, > >> 'content' is a proper superset of 'document', so if we were asked for > >> 'content' and can successfully parse it as 'document', we're good, > >> and if we see a DOCTYPE and yet it incurs a parse error as 'document', > >> well, that's what needed to happen. > > > > Hm, so, maybe just > > > > (1) always try to parse as document. If successful, we're done. > > > > (2) otherwise, if allowed by xmloption, try to parse using our > > current logic for the CONTENT case. > > What I don't like about that is that (a) the input could be > arbitrarily long and complex to parse (not that you can't imagine > a database populated with lots of short little XML snippets, but > at the same time, a query could quite plausibly deal in yooge ones), > and (b), step (1) could fail at the last byte of the input, followed > by total reparsing as (2). > > I think the safer structure is clearly that of the current patch, > modulo whether the "has a DOCTYPE" test is done by libxml itself > (with the assumptions you don't like) or by a pre-scan. > > So the current structure is: > > restart: > asked for document? > parse as document, or fail > else asked for content: > parse as content > failed? > because DOCTYPE? restart as if document > else fail > > and a pre-scan structure could be very similar: > > restart: > asked for document? > parse as document, or fail > else asked for content: > pre-scan finds DOCTYPE? > restart as if document > else parse as content, or fail > > The pre-scan is a simple linear search and will ordinarily say yes or no > within a couple dozen characters--you could *have* an input with 20k of > leading whitespace and comments, but it's hardly the norm. Just trying to > parse as 'document' first could easily parse a large fraction of the input > before discovering it's followed by something that can't follow a document > element. > > Regards, > -Chap >
Commits
-
Improve documentation about our XML functionality
- 728c49779ba8 11.6 landed
- 603a28b44973 10.11 landed
-
Improve documentation about our XML functionality.
- 12d46ac392d0 12.0 landed
-
Doc: clarify that REASSIGN OWNED doesn't handle default privileges.
- 50973687f185 9.6.13 cited
- 24df8662e4a4 11.3 cited
-
Suppress Append and MergeAppend plan nodes that have a single child.
- 8edd0e79460b 12.0 cited
-
Accept XML documents when xmloption = content, as required by SQL:2006+.
- 8d1dadb25bb5 12.0 landed
- da45927cef78 9.5.17 landed
- d7cfd5ee4591 9.6.13 landed
- 849f87a1c334 11.3 landed
- 78f84fe0f478 9.4.22 landed
- 754ffcd42006 10.8 landed
-
Ensure xmloption = content while restoring pg_dump output.
- 4870dce37fab 12.0 landed
- 8ba485422933 9.4.22 landed
- 08d8cfe3cfd6 9.5.17 landed
- de922529fe62 10.8 landed
- 7c89f350f109 11.3 landed
- 687acb598308 9.6.13 landed